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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BobKoenen
Helper IV
Helper IV

Unpivot by groups

Hi All, 

 

I have a table which looks like this but in reality has 20 Atr columns

 

CustomerAtr A1Atr B1Atr C1Atr A2Atr B2Atr C2Atr A3Atr B3Atr C3
APurpleIronkidsYellowPlasticTeensPinkPaperSenior
BGreenPlasticAdultBlackPlasticAdultWhiteWoodKids

  

And I want it to look like this 

 

CustomerAtr AAtr BAtr C
APurpleIron Kids
AYellowPlastic Teens
APink Paper Senior
BGreenPlasticAdult
BBlackPlasticAdult
BWhite Wood Kids

 

Have you got any Idea how to fix this?

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY5BCoQwDEXvkrWX0M0gbgQFGUoXxQYmNDQSK17fZCnM6v3wfuCHAD10MF96MFoYVaqhUD4NX2SW2z2ns9FuaUWsrmaqxZEOVOOClUQhdgEGOz9qtddfny9uxoHTXv6a7UfNJ2wi2TD5hBgf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, #"Atr A1" = _t, #"Atr B1" = _t, #"Atr C1" = _t, #"Atr A2" = _t, #"Atr B2" = _t, #"Atr C2" = _t, #"Atr A3" = _t, #"Atr B3" = _t, #"Atr C3" = _t]),
    Transformed = let cols = Table.ToColumns(Source), hdr = cols{0} in Table.Combine(List.Transform(List.Split(List.Skip(cols),3), each Table.FromColumns({hdr} & _)))
in
    Transformed

CNENFRNL_0-1662387434808.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY5BCoQwDEXvkrWX0M0gbgQFGUoXxQYmNDQSK17fZCnM6v3wfuCHAD10MF96MFoYVaqhUD4NX2SW2z2ns9FuaUWsrmaqxZEOVOOClUQhdgEGOz9qtddfny9uxoHTXv6a7UfNJ2wi2TD5hBgf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, #"Atr A1" = _t, #"Atr B1" = _t, #"Atr C1" = _t, #"Atr A2" = _t, #"Atr B2" = _t, #"Atr C2" = _t, #"Atr A3" = _t, #"Atr B3" = _t, #"Atr C3" = _t]),
    Transformed = let cols = Table.ToColumns(Source), hdr = cols{0} in Table.Combine(List.Transform(List.Split(List.Skip(cols),3), each Table.FromColumns({hdr} & _)))
in
    Transformed

CNENFRNL_0-1662387434808.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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