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 )
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"
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)
- Tvineyy6 years agoNew Member
Anonymous - please can you expand with an example?
I have a table with column headers "email", "name", "Address", followed by 3 headers that always change with the dataset - question 1, question 2 and question 3.
When I format the first headers it automatically moves them to the end.
How I can I reorder them back to the order above without explicitly mentioning the question 1-3 headers as these aren't defined -they change everytime.
- newts6 years agoRegular Visitor
Know this is old but hope it helps someone:
Where the previous step is Output and the column you want first is "Employee Number"
Reordered= Table.ReorderColumns(Output,List.Combine({{"Employee Number"},List.RemoveItems(Table.ColumnNames(Output),{"Employee Number"})}))