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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Pivoting Columns If Duplicate Value

Hey everyone

 

I think this should be fairly simple, but I am running circles with this question... I know this has something to do with pivoting columns, but I really can't find a way to do so.

 

Can someone support here, please?

 

My dataset:

Object TypeRecord NameStep: NameStep Last Actor: Full Name
OfferO-1Approval 1Albert Einstein
OfferO-2Approval 2Mickey Mouse
OfferO-2Approval 3Pluto Dog
OfferO-3Approval 2Bart Simpson
OfferO-4Approval 2Marge Simpson
OfferO-4Approval 3Homer Simpson
OfferO-5Approval 2Homer Simpson
OfferO-5Approval 4Peter Griffin
OfferO-5Approval 1Lisa Simpson
OfferO-5Approval 3Homer Simpson

 

My desired output:

 Approval 1Approval 2Approval 3Approval 4
O-1Albert Einstein   
O-2 Mickey MouseMickey Mouse 
O-3 Bart Simpson  
O-4 Marge SimpsonHomer Simpson 
O-5Lisa SimpsonHomer SimpsonMontgomery BurnsPeter Griffin
1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Place this M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k9LSy1S0lHy1zUEko4FBUX5ZYk5CmBOTlJqUYmCa2ZecUlqZp5SrA6yciNk5SCOb2Zydmqlgm9+aXEqPrXGQE5ATmlJvoJLfjqaQmN0Q50SgS4IzswtKM5Hd4AJhgMSi9JTiVEMssUjPze1CIdiU3STiVYMsiYgtQSo2L0oMy0NI9BM0cPYJ7M4kRiDsTg5FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Object Type" = _t, #"Record Name" = _t, #"Step: Name" = _t, #"Step Last Actor: Full Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Object Type", type text}, {"Record Name", type text}, {"Step: Name", type text}, {"Step Last Actor: Full Name", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Step: Name"]), "Step: Name", "Step Last Actor: Full Name")
in
    #"Pivoted Column"

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

7 REPLIES 7
AlB
Community Champion
Community Champion

Hi @Anonymous 

Place this M code in a blank query to see the steps:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k9LSy1S0lHy1zUEko4FBUX5ZYk5CmBOTlJqUYmCa2ZecUlqZp5SrA6yciNk5SCOb2Zydmqlgm9+aXEqPrXGQE5ATmlJvoJLfjqaQmN0Q50SgS4IzswtKM5Hd4AJhgMSi9JTiVEMssUjPze1CIdiU3STiVYMsiYgtQSo2L0oMy0NI9BM0cPYJ7M4kRiDsTg5FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Object Type" = _t, #"Record Name" = _t, #"Step: Name" = _t, #"Step Last Actor: Full Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Object Type", type text}, {"Record Name", type text}, {"Step: Name", type text}, {"Step Last Actor: Full Name", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[#"Step: Name"]), "Step: Name", "Step Last Actor: Full Name")
in
    #"Pivoted Column"

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Anonymous
Not applicable

@AlB thank you for your reply.

 

However, it doesn't fully work. I still have duplicates... This is what I have:

 

 Approval 1Approval 2Approval 3Approval 4
O-1Albert Einstein   
O-2 Mickey Mouse  
O-2  Mickey Mouse 
O-3 Bart Simpson  
O-4 Marge Simpson  
O-4  Homer Simpson 
O-5Lisa Simpson   
O-5 Homer Simpson  
O-5  Montgomery Burns 
O-5   Peter Griffin

 

Here is my code:

 

let
    Source = Table.Combine({#"BE DE NL Approvals (processes) Q1", #"BE DE NL Approvals (processes) Q2"}),
    #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[#"Step: Name"]), "Step: Name", "Step Last Actor: Full Name")
in
    #"Pivoted Column"

 

AlB
Community Champion
Community Champion

@Anonymous 

Not sure what you did. If I paste my code in a blank query I get exactly your expected result. I don't have the queries #"BE DE NL Approvals (processes) Q1" or  #"BE DE NL Approvals (processes) Q2"  so I cannot see the result of the code you've provided.

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

Anonymous
Not applicable

Sorry, I was not precise enough.

 

Yes, when I paste your code into blank query it works as expected - thank you.

 

However, when I am trying to do the same with my "true" dataset, above you can see the result. The column "Step Last Actor: Full Name" is being split and moved to columns - this is OK. However, in case of your query I have only one row per each "Record Name" (which is the desired result). In the case of my "true" dataset, this is not happening.

 

Would you happen to know why?

AlB
Community Champion
Community Champion

@Anonymous 

I cannot help if I don't see the actual dataset (or something that has the same structure)

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Hi

As tested, there are other columns in your data, so AlB's method won't work for you.

 

Best Regards

Maggie

Anonymous
Not applicable

You are right, I cleaned up the data a bit and now solution from @AlB works perfectly. Thank you so much!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.