Forum Discussion

mrbajana's avatar
mrbajana
Helper III
7 years ago
Solved

PowerQuery Unpivot o Pivot

Spoiler
 

I have this case where the data is received in this structure per year and 12 months in every column. As I do in PowerQuery so that it is in a structure which I can model for the reports.

 

Received:

 

Wanted:

 

 

Data : https://1drv.ms/x/s!Amrv4wqX-_hsinzPJ4TTNc41DhMN

 

3 Replies

  • Michiel's avatar
    Michiel
    Resolver III

    The main 'trick' is called exactly what you ask for: unpivot columns. Or: unpivot other columns, which is often more useful. It takes the name of columns and turns these into values in a new colum, and unpivots the rest.

     

    The problem in your file is that you have three rows containing labels, and you need one column header for unpivot to work. I would do it this way:

    1. Transpose everything (Transpose is also a Power Query transformation)

    2. The top three rows will be the first three columns. Merge these into one by concatenating the values (I would insert a delimiter between them)

    3. Transpose everything back

    4. Use the 'Use first row as headers' option to turn the now combined labels as column headers

    5. Unpivot

    6. Split the column with the header again into three separate columns.