cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gangula
Advocate II
Advocate II

Reorder columns based on column headers

I have created a function which renames my columns based on the criteria I need with numbers in all the column headers.

So I need to order these columns based on these numbers in ascending order. See the below code where I manually ordered the columns.

 

Table.ReorderColumns(RemoveColumns,{"Viewfolder 1", "Viewfolder 2", "View 2", "Viewfolder 3", "View 3"})

This is a sample case with just 5 columns, but I have excel files with 100's of columns to order.

I prefer it if "viewfolder" is placed before "view", but it's not mandatory. Is there any way to achieve this using "M"

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Gangula,

This post should have the solution you are looking for. 

View solution in original post

3 REPLIES 3
jhauff77060
Advocate II
Advocate II

You should be able to add a new step in Power Query as follows:

Home > Choose Columns > Select All Columns > Sort A-Z > Name

as shown in the YouTube video Easy Trick for Sorting Columns in Power Query 

Sort.jpg

Anonymous
Not applicable

@Gangula,

This post should have the solution you are looking for. 

View solution in original post

Thank you, that helped.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!