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
Rossmon
New Member

Removing 1st column duplicates but keeping the information.

This seems kind of unique, but may not be.  I'm in a new role and learning Power BI.

I have a table of information coming from a dataflow set to automatically update.  I need to use this as a dimension table, however some items have multiple entries (because of multiple accessories) and I need to clean the data in order to reach a one to many relationship.

Basically I am looking to have the 2nd and 3rd Accessory feed into additional columns.  

 

To simplify, this is the start:

ItemAccessory
Item 1Accessory 1A
Item 2Accessory 2A
Item 2Accessory 2B
Item 3Accessory 3A
Item 3Accessory 3B
Item 3Accessory 3C
Item 4Accessory 4A
Item 5Accessory 5A
Item 5 Accessory 5B
Item 6Accessory 6A

 

and this is my desired result:

Item1st Acc2nd Acc3rd Acc
Item 1Accessory 1A  
Item 2Accessory 2AAccessory 2B 
Item 3Accessory 3AAccessory 3BAccessory 3C
Item 4Accessory 4A  
Item 5Accessory 5AAccessory 5B 
Item 6Accessory 6A  

 

 

Thanks for the help in advance!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ixJzVUwVNJRckxOTi0uzi+qVDB0VIrVgcoYocgY4ZZxQsgYo8gYO+KUwa3HGSFjgiJjgmSaKYqMKW4ZJHvMUGTMgHpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Accessory = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Item"}, {{"ar", each Table.Transpose(Table.SelectColumns(_, {"Accessory"}))}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"Column1", "Column2", "Column3"}, {"Acc1", "Acc2", "Acc3"})
in
    #"Expanded ar"

Screenshot 2021-06-09 145719.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("i45W8ixJzVUwVNJRckxOTi0uzi+qVDB0VIrVgcoYocgY4ZZxQsgYo8gYO+KUwa3HGSFjgiJjgmSaKYqMKW4ZJHvMUGTMgHpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Accessory = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Item"}, {{"ar", each Table.Transpose(Table.SelectColumns(_, {"Accessory"}))}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"Column1", "Column2", "Column3"}, {"Acc1", "Acc2", "Acc3"})
in
    #"Expanded ar"

Screenshot 2021-06-09 145719.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
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.