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
QZ
Frequent Visitor

(M language)How to change columns to rows by Power Query

I have original data like bellow:

QZ_0-1680148742100.png

 

May I know how to transform to bellow format?

QZ_2-1680148982631.png

 

Actually, my final purpose is create a report(refer bellow picture) base on the data.

QZ_1-1680148858694.png

 

1 ACCEPTED SOLUTION
KeyurPatel14
Resolver IV
Resolver IV

Hi @QZ ,
Please try below M Code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY31DdU0lFyS0wuyS+qVACxfROTMzLzUkFMQz0IaQQmjZVidQjpAqk0Ausy0oOwidFlDGQag3UZg3UZo+oywudCEzBpCibNiNAFcZUJmDQFk8TogrjQBEyagkmgrlgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Process Date" = _t, Area = _t, Machine = _t, EOP1 = _t, EOP2 = _t, EOP3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Process Date", type date}, {"Area", type text}, {"Machine", type text}, {"EOP1", type number}, {"EOP2", type number}, {"EOP3", type number}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Process Date", "Area", "Machine"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Machine]), "Machine", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute", "Period"}})
in
#"Renamed Columns"

If this helps then mark it as a solution.
Thank you.

Sample output:

KeyurPatel14_0-1680149954219.png

 

View solution in original post

3 REPLIES 3
QZ
Frequent Visitor

It's works, thanks!👍

KeyurPatel14
Resolver IV
Resolver IV

Hi @QZ ,
Please try below M Code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY31DdU0lFyS0wuyS+qVACxfROTMzLzUkFMQz0IaQQmjZVidQjpAqk0Ausy0oOwidFlDGQag3UZg3UZo+oywudCEzBpCibNiNAFcZUJmDQFk8TogrjQBEyagkmgrlgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Process Date" = _t, Area = _t, Machine = _t, EOP1 = _t, EOP2 = _t, EOP3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Process Date", type date}, {"Area", type text}, {"Machine", type text}, {"EOP1", type number}, {"EOP2", type number}, {"EOP3", type number}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Process Date", "Area", "Machine"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Machine]), "Machine", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute", "Period"}})
in
#"Renamed Columns"

If this helps then mark it as a solution.
Thank you.

Sample output:

KeyurPatel14_0-1680149954219.png

 

KeyurPatel14
Resolver IV
Resolver IV

Hi @QZ ,
You can do this with Unpivot option in Power Query.

Try this and let me know if you have any queries.

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