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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Transpose table based on criteria

Hi, I have a table like this:

mhv22_0-1668092071783.png

and need to transpose and get a table like this:

mhv22_1-1668092131832.png

is that possible?
Thanks in advance!!!

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I download your sample, but I can't do M transformation because can't connet to the data source. Based on that, I create a demo.

vkalyjmsft_0-1668154901721.png

Here's my solution.

1.Group rows based on PRODUCTNUMBER, and transform the list to record.

= Table.Group(Source, {"PRODUCTNUMBER"}, {{"New", each Record.FromList(_[ATTRIBUTETYPENAME],{"Dexter-ecommerce","Jerarquia principal","Jerarquia secundaria marcas"})}})

Result:

vkalyjmsft_1-1668155044211.png

2.Expand the new column. Get the result:

vkalyjmsft_2-1668155076417.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRx9DK1NDBR0gEyPV0cg5VidVBEfV1dPB2DFTz8fZ2CXLFLIouaYjXIFJ9BphgGBRqaGxgCRf29/ENwiSqE+nkGu0agS8LsjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PRODUCTNUMBER = _t, ATTRIBUTETYPENAME = _t]),
    #"Grouped Rows" = Table.Group(Source, {"PRODUCTNUMBER"}, {{"New", each Record.FromList(_[ATTRIBUTETYPENAME],{"Dexter-ecommerce","Jerarquia principal","Jerarquia secundaria marcas"})}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "New", {"Dexter-ecommerce", "Jerarquia principal", "Jerarquia secundaria marcas"}, {"Count.Dexter-ecommerce", "Count.Jerarquia principal", "Count.Jerarquia secundaria marcas"})
in
    #"Expanded Count"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, I download your sample, but I can't do M transformation because can't connet to the data source. Based on that, I create a demo.

vkalyjmsft_0-1668154901721.png

Here's my solution.

1.Group rows based on PRODUCTNUMBER, and transform the list to record.

= Table.Group(Source, {"PRODUCTNUMBER"}, {{"New", each Record.FromList(_[ATTRIBUTETYPENAME],{"Dexter-ecommerce","Jerarquia principal","Jerarquia secundaria marcas"})}})

Result:

vkalyjmsft_1-1668155044211.png

2.Expand the new column. Get the result:

vkalyjmsft_2-1668155076417.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRx9DK1NDBR0gEyPV0cg5VidVBEfV1dPB2DFTz8fZ2CXLFLIouaYjXIFJ9BphgGBRqaGxgCRf29/ENwiSqE+nkGu0agS8LsjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PRODUCTNUMBER = _t, ATTRIBUTETYPENAME = _t]),
    #"Grouped Rows" = Table.Group(Source, {"PRODUCTNUMBER"}, {{"New", each Record.FromList(_[ATTRIBUTETYPENAME],{"Dexter-ecommerce","Jerarquia principal","Jerarquia secundaria marcas"})}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "New", {"Dexter-ecommerce", "Jerarquia principal", "Jerarquia secundaria marcas"}, {"Count.Dexter-ecommerce", "Count.Jerarquia principal", "Count.Jerarquia secundaria marcas"})
in
    #"Expanded Count"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-yanjiang-msft  thanks a lot!!!!

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
as I don't have access to your data sources, the file in the link you've provided doesn't work for me.
Also: What does the error-message say?
Please provide sample data in a usable form.

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

ImkeF
Community Champion
Community Champion

Yes, that's what I expected.
Please post some sample data here so I can check the code:
How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

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

Anonymous
Not applicable

@ImkeF  I think I did it with dynamic column, but I can´t do the same with "172" table.  table 85  is the one of the post example.  https://drive.google.com/file/d/1ze0w5JXhiaNca8yd7YQwEV5qxgV_1x5o/view?usp=share_link
I need to transpose table 172, but I m getting error.

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
check the last column -> Transform: Unpivot -> select 2nd column as Value column -> Advanced Options: Don't aggregate

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

Anonymous
Not applicable

@ImkeF  thanks for the answer but I m not getting the output expected...I need 4 columns as result, and the 3 levels of last column as 3 columns...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors