Table.ReorderColumns
This function retrieves a table from the input table, arranging the columns according to the specified column order. Columns that are not mentioned in the list will remain in their original order. An ...
Table.ReorderColumns(table as table, columnOrder as list, optional missingField as nullable number) as table
This function retrieves a table from the input table, arranging the columns according to the specified column order. Columns that are not mentioned in the list will remain in their original order. An exception will be raised if a specified column does not exist, unless the optional parameter missingField is used to specify an alternative action (e.g. MissingField.UseNull or MissingField.Ignore).
To rearrange the columns [Phone] and [Name] in the table using Power Query M, you can use the MTable.ReorderColumns function. For example, if you have a table with a record for CustomerID 1, where Phone is "123-4567" and Name is "Bob", you can switch the order of the columns by specifying the desired order as {"Name", "Phone"}. This will output a table with the columns in the new order, like so: Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}).
If you want to switch the columns [Phone] and [Address], or handle the case where [Address] doesn't exist in the table, you can use the ReorderColumns function with the MissingField.Ignore option. This will ensure that the table remains unchanged if the specified column doesn't exist. For example, if you have a table with a record for CustomerID 1, where Name is "Bob" and Phone is "123-4567", you can switch the order of the columns by specifying {"Phone", "Address"} and using MissingField.Ignore. This will output the table as Table.FromRecords(