Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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:
| SKU | Yes/No | Color | Data |
| H515322623 | Exclude | TRUE | |
| M32523623 | Include | Yellow | TRUE |
| M32523623 | Include | Blue | TRUE |
| S325923512 | Include | Yellow | TRUE |
| S325923512 | Include | Blue | TRUE |
| S325923512 | Include | Black | TRUE |
| D21523652 | Include | Yellow | TRUE |
| D21523652 | Include | Blue | TRUE |
| D21523652 | Include | White | TRUE |
| F36262362 | Exclude | TRUE | |
| J236277244 | Exclude | TRUE | |
| K235238692 | Include | Yellow | TRUE |
| K235238692 | Include | Blue | TRUE |
| K235238692 | Include | Black | TRUE |
| L236234774 | Include | Yellow | TRUE |
| L236234774 | Include | Red | TRUE |
| L236234774 | Include | Black | TRUE |
| Q135236243 | Exclude | TRUE | |
| U392582352 | Exclude | TRUE | |
| T2184914 | Include | White | FALSE |
| B3285203 | Exclude | Red | FALSE |
And i am trying to get to the following pivot:
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.
Solved! Go to Solution.
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"
| 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! |
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"
| 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! |
@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]
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 33 | |
| 29 |
| User | Count |
|---|---|
| 134 | |
| 96 | |
| 78 | |
| 67 | |
| 65 |