Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Artur_
Frequent Visitor

Row values to column

hi!

I have a table where a basic row is by milestone (blue table) and I have to rearrange it so that it is by code (black table).

2020-06-15-New CeT tracker.xlsm - Excel.gif

 

 

 

 

 

Could you please help me with that challenge?

Artur

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Take a look at this M code. It returns this table.

2020-06-15 07_17_40-Untitled - Power Query Editor.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMUtJRcgRiQ31DfSMDIwMg01LfEsKM1YGpcAJiI4QKQwN9IIKoiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Milestone = _t, #"Planned Date" = _t, #"Actual Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Milestone", type text}, {"Planned Date", type date}, {"Actual Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Code", "Milestone"}, "Attribute", "Value"),
    #"Merged Columns" = Table.CombineColumns(#"Unpivoted Other Columns",{"Milestone", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Attribute.1"),
    #"Added Prefix" = Table.TransformColumns(#"Merged Columns", {{"Attribute.1", each "Milestone " & _, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Attribute.1]), "Attribute.1", "Value")
in
    #"Pivoted Column"

1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

Take a look at this M code. It returns this table.

2020-06-15 07_17_40-Untitled - Power Query Editor.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WioiMUtJRcgRiQ31DfSMDIwMg01LfEsKM1YGpcAJiI4QKQwN9IIKoiQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Milestone = _t, #"Planned Date" = _t, #"Actual Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Milestone", type text}, {"Planned Date", type date}, {"Actual Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Code", "Milestone"}, "Attribute", "Value"),
    #"Merged Columns" = Table.CombineColumns(#"Unpivoted Other Columns",{"Milestone", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Attribute.1"),
    #"Added Prefix" = Table.TransformColumns(#"Merged Columns", {{"Attribute.1", each "Milestone " & _, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Attribute.1]), "Attribute.1", "Value")
in
    #"Pivoted Column"

1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors