Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
himanshu23
Regular Visitor

How to pivot with multiple values column?

himanshu23_0-1632398574153.png

I have data in the above format. I want to convert it in the format mentioned below:

himanshu23_1-1632398664977.png
In excel I used to do it through sumifs, but that was really time consuming. I want to do it through power query. I tried pivoting, but it asks me to identify single value column, and as I have three value columns. I don't get the data in the format I want.
How to do it?
Please help and thanks.

 

 

1 ACCEPTED SOLUTION

Hi @himanshu23 ,

 

First go to query editor,select columns "Qreach,Qrem,Qsold">"unpivot columns",and you will get a table as below:

vkellymsft_0-1632727698062.png

Then back to Report view,create a matrix,and you will see:

vkellymsft_1-1632727738701.png

For the related .pbix file,pls see attached.

 

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

View solution in original post

5 REPLIES 5
mahoneypat
Microsoft Employee
Microsoft Employee

If you do decide to restructure your data, here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYyxDQAgCAR3obZQXgfQNYj7ryE+hlhcwT05M2m1SpHpNEfJLiaa/jo4gx7p8bZOH53FOzZ8nfVczz7SK9v83wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PROID = _t, Store = _t, M1 = _t, M2 = _t, M3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PROID", Int64.Type}, {"Store", type text}, {"M1", Int64.Type}, {"M2", Int64.Type}, {"M3", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Record.RenameFields(Record.RemoveFields(_, {"PROID", "Store"}), {{"M1", [Store] & " M1"}, {"M2", [Store] & " M2"}, {"M3", [Store] & " M3"}})),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"M1", "M2", "M3"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Store]), "Store", "Custom"),
    #"Expanded A" = Table.ExpandRecordColumn(#"Pivoted Column", "A", {"A M1", "A M2", "A M3"}, {"A M1", "A M2", "A M3"}),
    #"Expanded B" = Table.ExpandRecordColumn(#"Expanded A", "B", {"B M1", "B M2", "B M3"}, {"B M1", "B M2", "B M3"})
in
    #"Expanded B"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


himanshu23_0-1632401963984.png

This is coming, not what I need

 

Hi @himanshu23 ,

 

First go to query editor,select columns "Qreach,Qrem,Qsold">"unpivot columns",and you will get a table as below:

vkellymsft_0-1632727698062.png

Then back to Report view,create a matrix,and you will see:

vkellymsft_1-1632727738701.png

For the related .pbix file,pls see attached.

 

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

mahoneypat
Microsoft Employee
Microsoft Employee

You could make that in a matrix visual, but are you sure you want to restructure your data?  It is set up well for analysis now.  Also, in the query editor, you won't be able to end up with the two columns with the same name.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


I need to create reports in my organisation's format. I need to load it in excel only, that's how they want it.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.