Imported columns are 1, 10, 100, 101 ... instead of 1, 2, 3, 4 ...

Monsignor

Board Regular
Joined
May 30, 2011
Messages
162
What is a way to correct this when the dataset needs to be imported in numerical order, and not the order shown in the image below?


Columns-out-of-order.png
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
First I would like to remark that this looks strange to me: usually you would get the Columns in the same order as in the source table.

Anyhow, my suggestion is to add a column with your columns sorted on number.
In the code below, #"Renamed Columns" is the name of the preceding step and then proceed from there.

Code:
    ColumnsSorted = Table.AddColumn(#"Renamed Columns","ReorderedTable", each 
                    Table.ReorderColumns([Import.Data],
                    let
                        ColumnNames = Table.ColumnNames(#"Renamed Columns"[Import.Data]{0}),
                        ColumnNumbers = List.Transform(ColumnNames, each Number.From(Text.Replace(_, "Column",""))),
                        #"Sorted Items" = List.Sort(ColumnNumbers,Order.Ascending),
                        ColumnNamesSorted = List.Transform(#"Sorted Items", each "Column"&Text.From(_))
                    in
                        ColumnNamesSorted))
 
Last edited:
Upvote 0
Marcel, this is certainly weird. I saw this problem months ago and it went away. Now I'm working with someone and she's getting this problem. I don't know if it's because the source file is a .xls or what.
 
Upvote 0
That question becomes too technical for me.
Otherwise I'm curious if my solution worked for you.
 
Upvote 0
Marcel, sorry. I'm having a hard time even reproducing the problem. So, I haven't been able to apply your solution. This is the strangest thing. I'm at a loss.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top