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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
bvbull200
Helper III
Helper III

How to Pivot Column w/Different Number of Values

I don't know if that title accurately describes what I'm looking for, but here it goes.

 

I have a table with two columns.  The first column is a unique key - let's say a part #.  The second column is an attribute.  Some keys have 1 attribute, some keys have multiple attributes.  What I need to do is put each attribute in a column next to the key so that each key only takes up a single row.  For instance, I need this:

 

KeyAttribute
PartABCBlue
PartXYZ

Red

PartXYZRound
PartXYZSlim
Part123Black
Part123Square

 

To convert to:

 

KeyAttribute.1Attribute.2Attribute.3
PartABCBlue  
PartXYZRedRoundSlim
Part123BlackSquare 

 

Any help to this end is greatly appreciated!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@bvbull200 , you can first group by key column and then extract attributes,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKnF0clbSUXLKKU1VitWBCEVERgGFglJT0EXyS/PQxYJzMnPhQoZGxmCzEpOz0cSCC0sTi4A2xAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Attribute = _t]),

    #"Grouped Rows" = Table.Group(
        Source,
        {"Key"},
        {{"Attr", each Table.Transpose(Table.SelectColumns(_,{"Attribute"}))}}
    ),
    #"Expanded Attr" = Table.ExpandTableColumn(#"Grouped Rows", "Attr", {"Column1", "Column2", "Column3"}, {"Attr.Column1", "Attr.Column2", "Attr.Column3"})
in
    #"Expanded Attr"

Screenshot 2021-02-17 232726.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

@bvbull200 , you can first group by key column and then extract attributes,

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgsKnF0clbSUXLKKU1VitWBCEVERgGFglJT0EXyS/PQxYJzMnPhQoZGxmCzEpOz0cSCC0sTi4A2xAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Attribute = _t]),

    #"Grouped Rows" = Table.Group(
        Source,
        {"Key"},
        {{"Attr", each Table.Transpose(Table.SelectColumns(_,{"Attribute"}))}}
    ),
    #"Expanded Attr" = Table.ExpandTableColumn(#"Grouped Rows", "Attr", {"Column1", "Column2", "Column3"}, {"Attr.Column1", "Attr.Column2", "Attr.Column3"})
in
    #"Expanded Attr"

Screenshot 2021-02-17 232726.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
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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors