This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
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]
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 32 | |
| 26 | |
| 21 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 65 | |
| 43 | |
| 28 | |
| 24 | |
| 22 |