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
partymia
Frequent Visitor

How to make a pivot using Power Query

Hello,

 

I am trying to build a pivot table using Power Query to later feed into my normal table as values but am quite unsure how to proceed. In excel is quite easy but in Power Bi not so much. I have the following raw data:

 

SKUYes/NoColorData
H515322623Exclude TRUE
M32523623IncludeYellowTRUE
M32523623IncludeBlueTRUE
S325923512IncludeYellowTRUE
S325923512IncludeBlueTRUE
S325923512IncludeBlackTRUE
D21523652IncludeYellowTRUE
D21523652IncludeBlueTRUE
D21523652IncludeWhiteTRUE
F36262362Exclude TRUE
J236277244Exclude TRUE
K235238692IncludeYellowTRUE
K235238692IncludeBlueTRUE
K235238692IncludeBlackTRUE
L236234774IncludeYellowTRUE
L236234774IncludeRedTRUE
L236234774IncludeBlackTRUE
Q135236243Exclude TRUE
U392582352Exclude TRUE
T2184914IncludeWhiteFALSE
B3285203ExcludeRedFALSE

And i am trying to get to the following pivot:

Capture.PNG

Is it possible to do in Power query, as i need the results from last column to link back to my SKU in the main tables basically? Thanks for the help in advance. 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdLPC4IwFAfw/2VnD+29zekxSemHHfIHEeIhVCgadUnqz29qgppjwQ6Dfdj3vbdlGVlzyhHABiQW8d+FrMtK7dRKotQnuZWRPQIH7MTm3otTJeXjZXaerKuhipVyATkFw3Ua+Od9njwXt6FbAW2q46bYeTdNnVfHy/U5YoEah93MRDvcbXMqBDCmJTvVHaBju6bSNXBau5ZNJha2j8mEYIZcDYyq8g/1E3ug2H4jpv+RKbrAnaYNLUmAOsyl46z+fYJlGHfMQ3A4LMZRXeFflH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SKU = _t, #"Yes/No" = _t, Color = _t, Data = _t]),
    #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[Color]), "Color", "Data", List.Count),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Sum", each List.Sum(List.Skip(Record.ToList(_),2)))
in
    #"Added Custom"

Screenshot 2021-05-26 091549.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdLPC4IwFAfw/2VnD+29zekxSemHHfIHEeIhVCgadUnqz29qgppjwQ6Dfdj3vbdlGVlzyhHABiQW8d+FrMtK7dRKotQnuZWRPQIH7MTm3otTJeXjZXaerKuhipVyATkFw3Ua+Od9njwXt6FbAW2q46bYeTdNnVfHy/U5YoEah93MRDvcbXMqBDCmJTvVHaBju6bSNXBau5ZNJha2j8mEYIZcDYyq8g/1E3ug2H4jpv+RKbrAnaYNLUmAOsyl46z+fYJlGHfMQ3A4LMZRXeFflH8A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SKU = _t, #"Yes/No" = _t, Color = _t, Data = _t]),
    #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[Color]), "Color", "Data", List.Count),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Sum", each List.Sum(List.Skip(Record.ToList(_),2)))
in
    #"Added Custom"

Screenshot 2021-05-26 091549.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@partymia , You need unpivot color and data column. then use count when you do unpivot 

https://radacad.com/pivot-and-unpivot-with-power-bi

After that add another column, which sum these new 5 columns 

= [Yellow] +[blue] +[red] +[white] + [black]

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.