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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
emaeorg
New Member

Unpivoting 3 sets of columns without duplicated data

Hi! 

 

Looking for some advice regarding unpivoting a table with 3 sets of data. I haven't gotten over an issue, where data gets duplicated once you unpivot 2nd and 3rd set. 

 

Example:

IDCategory 1Category 2Category 3Product 1Product 2Product 3Adjective 1Adjective 2Adjective 3
1RedBlueGreenApplePeach BigTasty 
2Blue  BananaPearOrangeSmall  
3GreenRed Pear  Round  

 

What I want to do is to unpivot these columns in order to count the categories, product and adjectives as well as use them in slicers. 

 

From the example table, the preferred result should be:

IDCategoryProductAdjective
1RedAppleBig
1BluePeachTasty
1Greennullnull
2BlueBananaSmall
2nullPearnull
2nullOrangenull
3GreenPearRound
3Rednullnull

 

Original source in Sharepoint Excel workbook is updated regularly with new rows. There are some other columns like date, relevant personel and some other categories, where unpivoting is not needed. ID is the only unique value. I can not alter the source. 

 

Any help is greatly appreciated.

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

3 REPLIES 3
ThxAlot
Super User
Super User

Easy enough,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKTQGSTjmlqUDKvSg1NQ9IOxYU5ID4AamJyRlAGqQiMx1IhiQWl1SCBGJ1opWMEBqhahLzgBCirwhI+Rcl5qWDpINzE3NyoMpAOo2R7II4AKEJgoLyS/NSYDpiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Category 1" = _t, #"Category 2" = _t, #"Category 3" = _t, #"Product 1" = _t, #"Product 2" = _t, #"Product 3" = _t, #"Adjective 1" = _t, #"Adjective 2" = _t, #"Adjective 3" = _t]),
    #"Added Column" = Table.AddColumn(Source, "tb", each let row=Record.ToList(_) in Table.FromColumns(List.Split(List.Skip(row),3))),
    #"Expanded tb" = Table.ExpandTableColumn(Table.SelectColumns(#"Added Column",{"ID", "tb"}), "tb", {"Column1", "Column2", "Column3"}, {"Category", "Product", "Adjective"})
in
    #"Expanded tb"

ThxAlot_0-1715602403489.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Ahmedx
Super User
Super User

pls try this

Screenshot_1.png

Thanks, this works great!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.