Transform one to many data to columns

狂风中的少年 提交于 2021-02-05 08:10:52

问题


Given this data:

data source

How do I transform it to look like this:

target output

There are two columns in the data source, key (title) and value (responsibility). I need to transform it such that we have the key column (title) and then n columns where n is the highest number of value a key has, eg 3 in the picture above. Hence the columns should be:

Title, 1, 2, 3.

The values in each column 1, 2, 3 should be corresponding to values in the original data.

Any combination of formula is welcomed - I believe a combination of Transpose and/or Query (pivot) is appropriate but I cannot put it together.

In case this is too complex we can put an enumeration directly in the data source, but it would be nice to be able to have the formula work without it. Eg:

enter image description here

Example sheet: https://docs.google.com/spreadsheets/d/1InYZ12VuuaSg0s3fiFTCx8BnwEan5JsqpsNBF973lWc/edit?usp=sharing


回答1:


try:

=QUERY({A:C}, 
 "select Col1,max(Col3) 
  where Col1 is not null 
  group by Col1 
  pivot Col2", 1)


or:

=ARRAYFORMULA(QUERY({A:A, COUNTIFS(A:A, A:A, ROW(A:A), "<="&ROW(A:A)), B:B}, 
 "select Col1,max(Col3) 
  where Col1 is not null 
  group by Col1 
  pivot Col2", 1))



来源:https://stackoverflow.com/questions/60191001/transform-one-to-many-data-to-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!