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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Dynamic unpivot of columns in Power Query

Hi,

I am using the function = Table.Unpivot(#"Filtered Rows1", {"x","y","z"...}, "Attribute", "Value") to unpivot a table by those selected rows.

 

However, they are input values and will change and when they change I get the error that a column header is missing.

How do I write this in a way that -instead of listing out the column headings to unpivot {"x","y","z"...}, I can select all columns beginning with column 4 to the end.  Is it doable?

Regards

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Something like:

= Table.Unpivot(#"Filtered Rows1", List.RemoveFirstN(Table.ColumnNames(#"Filtered Rows1"),3), "Attribute", "Value") 

View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Flip the operation on its head: Select all the columns you DON'T want to unpivot, then go to Transform tab > Unpivot Columns (dropdown) > Unpivot OTHER columns.

 

This will generate code like this instead:

Table.UnpivotOtherColumns(previousStep, {"fixedColumnA", "fixdColumnB"}, "Attribute", "Value")

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




ronrsnfld
Super User
Super User

Something like:

= Table.Unpivot(#"Filtered Rows1", List.RemoveFirstN(Table.ColumnNames(#"Filtered Rows1"),3), "Attribute", "Value") 

mathur786_0-1713639083028.png

 

mathur786_1-1713639117718.png

 

mathur786_2-1713639140540.png

 

 

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Top Solution Authors
Top Kudoed Authors