How do I combine cells from different columns on the same row to cells on different rows in the same column?

╄→尐↘猪︶ㄣ 提交于 2020-01-06 08:30:25

问题


I have data coming in a certain way, but I need it automatically converted into a different layout for a specific chart in Google Data Studio.

Basically, I want to go from this

Date    Apple   Banana   Cherry

Jan 1   500     800      2000
Jan 2   800     920      2878
Jan 3   1700    1850     3000

To this:

Date     Type     Amount

Jan 1    Apple    500
Jan 1    Banana   800 
Jan 1    Cherry   2000
Jan 2    Apple    800
Jan 2    Banana   920
Jan 2    Cherry   2878
Jan 3    Apple    1700
Jan 3    Banana   1850
Jan 3    Cherry   3000

I can't think of a solution (I'm relatively new at this). I'm hoping someone might be able to point me in the right direction. Thanks in advance for any help I can get!


回答1:


ultimate 720° freedom with no limits:

=ARRAYFORMULA({"Date", "Type", "Amount"; 
 SPLIT(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(B2:Z<>"", A2:A&"♠"&B1:1&"♠"&B2:Z&"♦", )), , 500000)), , 500000)), "♦")), "♠")})




回答2:


If you haven't got too many rows and columns, you can use a split/join approach:

=ArrayFormula({"Date","Type","Amount";split(transpose(split(textjoin("♫",,A2:A4&"♪"&B1:D1&"♪"&B2:D4),"♫")),"♪")})

Because this combines the data into a single cell before splitting it, there is a limit of 50,000 characters on the data plus separator characters.



来源:https://stackoverflow.com/questions/55427804/how-do-i-combine-cells-from-different-columns-on-the-same-row-to-cells-on-differ

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