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 September 15. Request your voucher.

Reply
Linksys45
Frequent Visitor

Unpivoting multiple (or combination of) columns of data

Hey everyone,

 

New to BI, so bare with me. I am working in Power Query, but am really having trouble untangaling data and how it is formatted.

 

Here is the example of the current state:

Comapny Name

Initiative 1Description for Initiative 1Goal for Initiative 1Scope for Initiative 1Challenges for Initiative 1Initiative 2Description for Initiative 2Goal for Initiative 2Scope for Initiative 2Challenges for Initiative 2Initiative 3same columns as past two
Company 1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Company 2            
Company 3            
             

 

I don't know how to untangle it from being seperate columns to just rows like this (I'm guess some unpivoting but I've been unsuccessful so far). I want it to look like this:

Comapny Name

InitiativeDescription for InitiativeGoal for InitiativeScope for InitiativeChallenges for Initiative
Company 1Initiative 1xxxxxxxxxxxx
Company 1

Initiative 2

    
Company 1Initiative 3    
Company 2Initiative 1    
Company 2

Initiative 2

    
Company 2Initiative 3    
Company 3Initiative 1    
Company 3

Initiative 2

    
Company 3Initiative 3    

 

I've tried unpivoting only selected columns on each column of "Initiative X" column, but that only gets it half way as I am still stuck with all the value columns staying where they are with 3 repeating rows with only the initiaive column being different, so it  reads like this:

Comapny Name

Description for Initiative 1Goal for Initiative 1Scope for Initiative 1Challenges for Initiative 1Description for Initiative 2Goal for Initiative 2Scope for Initiative 2Challenges for Initiative 2Initiative
Company 1xxxxxxxxxxxxxxxxxxxxxxxxIntiative 1
Company 1Thisis all thesamedata onerowabove & BelowIntiative 2
Company 1xxxxxxxxxxxxxxxxxxxxxxxxInitiative 3
Company 2xxxxxxxxxxxxxxxxxxxxxxxxIntiative 1
Company 2Thisis all thesamedata onerowabove & BelowIntiative 2
Company 2xxxxxxxxxxxxxxxxxxxxxxxxInitiative 3

 

Is there any good way to do this?

 

Thanks!

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Comapny Name", type text}, {"Initiative 1", type text}, {"Description for Initiative 1", type text}, {"Goal for Initiative 1", type text}, {"Scope for Initiative 1", type text}, {"Challenges for Initiative 1", type text}, {"Initiative 2", type text}, {"Description for Initiative 2", type text}, {"Goal for Initiative 2", type text}, {"Scope for Initiative 2", type text}, {"Challenges for Initiative 2", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Comapny Name"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Comapny Name", type text}, {"Initiative 1", type text}, {"Description for Initiative 1", type text}, {"Goal for Initiative 1", type text}, {"Scope for Initiative 1", type text}, {"Challenges for Initiative 1", type text}, {"Initiative 2", type text}, {"Description for Initiative 2", type text}, {"Goal for Initiative 2", type text}, {"Scope for Initiative 2", type text}, {"Challenges for Initiative 2", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Comapny Name"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This worked exactly as I was looking for! Thank you :)!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-janeyg-msft
Community Support
Community Support

Hi, @Linksys45 

 

According to your description, I made some fake data and unpivot columns in PQ.

Like this:1.gif

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Linksys45 , This blog talks about unpivot twice

https://kohera.be/blog/power-bi/how-to-unpivot-twice/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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