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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
WencyREN
Frequent Visitor

Create pivot table using Power query

Spoiler
 

Dear, I have a dataset like below in PBI,  how do I create a table in Power query like the pivot table below, in which calculates the sum of sales value for each distinct product type A/B/C/D? (will need to consider adding other dimensions as well when proceeding further)

Thank you!

WencyREN_0-1653399986835.png

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Select Product column - Home menu - Group by

Under Operation, select Sum and under Column, select Sales value

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQpKTQGSjiCmLxCbKsXqQCQiU3Ny8stBck5Awg+ILcFyIJ57UWpqHpB2cgYS/kBsaASWc4Yb6OIGJAKA2AQu4V+UmJeeCtLtASQCgdhcKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Color = _t, Country = _t, City = _t, #"Sales value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Color", type text}, {"Country", type text}, {"City", type text}, {"Sales value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Sum of Sales value", each List.Sum([Sales value]), type nullable number}})
in
    #"Grouped Rows"

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Select Product column - Home menu - Group by

Under Operation, select Sum and under Column, select Sales value

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQpKTQGSjiCmLxCbKsXqQCQiU3Ny8stBck5Awg+ILcFyIJ57UWpqHpB2cgYS/kBsaASWc4Yb6OIGJAKA2AQu4V+UmJeeCtLtASQCgdhcKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Color = _t, Country = _t, City = _t, #"Sales value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Color", type text}, {"Country", type text}, {"City", type text}, {"Sales value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Sum of Sales value", each List.Sum([Sales value]), type nullable number}})
in
    #"Grouped Rows"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors