cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

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:

recived.png

 

Wanted:

 

desire.png

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: PowerQuery Unpivot o Pivot

Hi @mrbajana ,

I've created a handy function for a part of what @Michiel has described here: https://www.thebiccountant.com/2017/06/19/unpivot-by-number-of-columns-and-rows-in-powerbi-and-power...

 

After the unpivot, you simply have to select the column with the desired column names and pivot (back) on them.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
Highlighted
Resolver III
Resolver III

Re: PowerQuery Unpivot o Pivot

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.

Highlighted
Super User III
Super User III

Re: PowerQuery Unpivot o Pivot

Hi @mrbajana ,

I've created a handy function for a part of what @Michiel has described here: https://www.thebiccountant.com/2017/06/19/unpivot-by-number-of-columns-and-rows-in-powerbi-and-power...

 

After the unpivot, you simply have to select the column with the desired column names and pivot (back) on them.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

Highlighted
Helper I
Helper I

Re: PowerQuery Unpivot o Pivot

PowerQuery is Magic thank you very much for your help!!!

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.

Top Solution Authors
Top Kudoed Authors