问题
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