Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello all,
I'm missing what I'm hoping is a simple step here...
I have my data in this format:
Location | Type | Jan | Feb | Mar |
A | 1 | 0.1 | 0.2 | 0.1 |
A | 2 | 0.2 | 0.1 | 0.1 |
A | 3 | 0.1 | 0.1 | 0.12 |
B | 1 | 0.1 | 0.12 | 0.2 |
B | 2 | 0.12 | 0.2 | 0.2 |
B | 3 | 0.2 | 0.05 | 0.1 |
C | 1 | 0.2 | 0.1 | 0.05 |
C | 2 | 0.1 | 0.05 | 0.1 |
C | 3 | 0.05 | 0.2 | 0.12 |
and I wan't to get it to this format:
Location | Month | Type 1 | Type 2 | Type 3 |
A | Jan | 0.1 | 0.2 | 0.1 |
A | Feb | 0.2 | 0.1 | 0.1 |
A | Mar | 0.1 | 0.1 | 0.12 |
B | Jan | 0.1 | 0.12 | 0.2 |
B | Feb | 0.12 | 0.2 | 0.05 |
B | Mar | 0.2 | 0.2 | 0.1 |
C | Jan | 0.2 | 0.1 | 0.05 |
C | Feb | 0.1 | 0.05 | 0.2 |
C | Mar | 0.05 | 0.1 | 0.12 |
Any advice would be appreciated!
Thank you all,
Shmuel
Solved! Go to Solution.
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Location", "Type"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN")[Type]), "Type", "Value")
in
#"Pivoted Column"
Hope this helps.
Hi,
This M code works
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Location", "Type"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Type", type text}}, "en-IN")[Type]), "Type", "Value")
in
#"Pivoted Column"
Hope this helps.
Thank you! All I was missing was a pivot!
You are welcome.
Hi @sdukes ,
You can applied the unpivot and pivot steps in Power Query Editor to achieve it, the specific codes as below:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYgM9CGkEZcfqQOSMUERR5YxRRMGkEVjSCc1QQ5gpMEkjVGFUSWMkUQNTJDud4cYiuweoBCaJJoyq0xhZGO6A2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Type = _t, Jan = _t, Feb = _t, Mar = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Type", Int64.Type}, {"Jan", type number}, {"Feb", type number}, {"Mar", type number}}),
#"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"Jan", "Feb", "Mar"}, "Attribute", "Value"),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Unpivoted Only Selected Columns", {"Location", "Attribute", "Value"}, "Attribute.1", "Value.1"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Value.1", type text}}, "zh-CN"),{"Attribute.1", "Value.1"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Reordered Columns" = Table.ReorderColumns(#"Merged Columns",{"Location", "Attribute", "Merged", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Reordered Columns", List.Distinct(#"Reordered Columns"[Merged]), "Merged", "Value")
in
#"Pivoted Column"
Applied steps in Power Query EditorBest Regards
Rena
@sdukes check my blog post here which pretty much talk about the similar use case
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
142 | |
72 | |
62 | |
51 | |
48 |
User | Count |
---|---|
206 | |
90 | |
61 | |
59 | |
57 |