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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Lio123
Helper I
Helper I

Power Query Experts - Need your support please

Dear All,

I need your help in transforming the data in Power query. Please let me know how to achieve this.

Table I have is :

Lio123_0-1752671298567.png


And the format I want to convert the above table like below

Lio123_1-1752671354484.png

 

Thanks!!

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

You can select 'Country' and 'City' columns and choose 'Unpivot other columns' on the Transform ribbon.

Make sure the value column is a number.

Split the 'Attribute' column by delimiter (space).

Pivot on the 'Attribute.2' column, make sure aggregation is set to Sum on the value column.
Example code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUXIEYkMDAyBpagCmQNjIAEFCJA1NQaSxKUREKVYnWikSyHSCcEGaQQRYE4wwhOgDawOxlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, City = _t, #"Jan Payment" = _t, #"Jan Profit" = _t, #"Jan Loss" = _t, #"Feb Payment" = _t, #"Feb Profit" = _t, #"Feb Loss" = _t, #"Mar Payment" = _t, #"Mar Profit" = _t, #"Mar Loss" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Country", "City"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", type number}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Month", "Item"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Item]), "Item", "Value", List.Sum)
in
    #"Pivoted Column"

jgeddes_1-1752686717844.png

 

jgeddes_0-1752686703377.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
v-dineshya
Community Support
Community Support

Hi @Lio123 ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please follow below steps.

 

1. Created sample data based on your screenshot. Please refer below snap.

 

vdineshya_0-1752737414232.png

 

2. In Query editor, Click on "New source" --> "Blank Query" and click on "Advanced editor" remove the all code.

Please paste the below M code in "Advanced editor" and click "OK". 

 

vdineshya_2-1752737759874.png

 

let

Source = #table(
{"Country", "City", "Jan Payment", "Jan Profit", "Jan Loss", "Feb Payment", "Feb Profit", "Feb Loss", "Mar Payment", "Mar Profit", "Mar Loss"},
{
{"X", "A", 100, 5000, 0, 200, 200, 100, 150, 350, 10}
}
),


Unpivoted = Table.UnpivotOtherColumns(Source, {"Country", "City"}, "Attribute", "Value"),


SplitAttribute = Table.SplitColumn(
Unpivoted,
"Attribute",
Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv),
{"Month", "Metric"}
),


Pivoted = Table.Pivot(
SplitAttribute,
List.Distinct(SplitAttribute[Metric]),
"Metric",
"Value"
),


Reordered = Table.SelectColumns(Pivoted, {"Country", "City", "Month", "Payment", "Profit", "Loss"})
in
Reordered

 

3. Please refer output snap and attached PBIX file.

 

vdineshya_1-1752737704351.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

 

Hi @Lio123 ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

 

Regards,

Dinesh

jgeddes
Super User
Super User

You can select 'Country' and 'City' columns and choose 'Unpivot other columns' on the Transform ribbon.

Make sure the value column is a number.

Split the 'Attribute' column by delimiter (space).

Pivot on the 'Attribute.2' column, make sure aggregation is set to Sum on the value column.
Example code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilDSUXIEYkMDAyBpagCmQNjIAEFCJA1NQaSxKUREKVYnWikSyHSCcEGaQQRYE4wwhOgDawOxlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, City = _t, #"Jan Payment" = _t, #"Jan Profit" = _t, #"Jan Loss" = _t, #"Feb Payment" = _t, #"Feb Profit" = _t, #"Feb Loss" = _t, #"Mar Payment" = _t, #"Mar Profit" = _t, #"Mar Loss" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Country", "City"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", type number}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Month", "Item"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Item]), "Item", "Value", List.Sum)
in
    #"Pivoted Column"

jgeddes_1-1752686717844.png

 

jgeddes_0-1752686703377.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors