Forum Discussion
Reorder columns in Query Editor without listing the column names
- 9 years ago
hi majdkaid22,
You may reorder your columns in power query alphabetically using a custom code.
=Table.ReorderColumns( NameOfPreviousStep, List.Order( Table.ColumnNames( NameOfPreviousStep ), Order.Ascending )
hi majdkaid22,
You may reorder your columns in power query alphabetically using a custom code.
=Table.ReorderColumns( NameOfPreviousStep, List.Order( Table.ColumnNames( NameOfPreviousStep ), Order.Ascending )
In the Power Query editor for excel, the name of the function is List.Sort. I assume it's the exact equivalent because it worked fine, I didn't even check the arguments.
- Anonymous7 years agoNot applicable
This got me pointed in the right direction, maybe things have changed with time, but I had to make some adjustments to above for it to work:
Table.ReorderColumns(PreviousStep, List.Sort(Table.ColumnNames(PreviousStep),Order.Ascending))
- Ssibbett6 years agoFrequent Visitor
I like this subject. Is there a way to do this but omiting the first 4 columns?
First 4 columns would remain as: "Item Name","Package Type","Attribute","Item No"
- Anonymous6 years agoNot applicable
Yes, first create a list of the columns not to be sorted.
Then use List.RemoveItems to remove this list from the rest of the Table.ColumnNames items - this creates a list of columns to be sorted.
Then use List.Sort to sort those.
and then use List.Combine to Combine the not to be sorted columns and the sorted columns. (FinalOrder)
Last step:
Table.ReorderColumns(PreviousTable, FinalOrder)