Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Say I have a table like:
week # | blah0 | blah1 | blah2 |
41 | 2 | 1 | 1 |
42 | 1 | 3 | 0 |
43 | 0 | 2 | 1 |
Would it be possible to refactor it into the following using Power Query? If so, what would the code look like? I am very stumped.
id | week # | category |
1 | 41 | blah0 |
2 | 41 | blah0 |
3 | 41 | blah1 |
4 | 41 | blah2 |
5 | 42 | blah0 |
6 | 42 | blah1 |
7 | 42 | blah1 |
8 | 42 | blah1 |
9 | 43 | blah1 |
10 | 43 | blah1 |
11 | 43 | blah2 |
Any help is much appreciated! 🙂
Solved! Go to Solution.
Hi @ugh ,
the code could look like so:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFU0lEyAmJDMI7VAQrBuMZAbAARgjBhKmNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"week #" = _t, blah0 = _t, blah1 = _t, blah2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"week #", Int64.Type}, {"blah0", Int64.Type}, {"blah1", Int64.Type}, {"blah2", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"week #"}, "Attribute", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each {1..[Value]}),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Custom] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value", "Custom"}),
#"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type)
in
#"Added Index"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi @ugh ,
the code could look like so:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFU0lEyAmJDMI7VAQrBuMZAbAARgjBhKmNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"week #" = _t, blah0 = _t, blah1 = _t, blah2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"week #", Int64.Type}, {"blah0", Int64.Type}, {"blah1", Int64.Type}, {"blah2", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"week #"}, "Attribute", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each {1..[Value]}),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Custom] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value", "Custom"}),
#"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 1, 1, Int64.Type)
in
#"Added Index"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
So quick! Thank you this works! 😁
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Ask questions in Eventhouse and KQL, Eventstream, and Reflex.
User | Count |
---|---|
40 | |
30 | |
27 | |
18 | |
17 |