Table.ReorderColumns

D

T

The M Code Behind the Power Query M function Table.ReorderColumns

What is Table.ReorderColumns?

Table.ReorderColumns is a Power Query M function that rearranges the order of columns in a table. This function allows users to customize the order of columns in a table based on their needs.

Understanding the M Code Behind Table.ReorderColumns

The M code behind Table.ReorderColumns is relatively straightforward. It essentially reorders the list of column names in a table based on the user’s input.

Here’s an example of the M code:


Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtjQ0MjQ2NjY3Mq1TS0lWitWJVItKzUxNrA0MMY0NAMz1DMyMDQ0MDQ0MAQa", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),

ReorderedColumns = Table.ReorderColumns(Source,{"Column4", "Column1", "Column2", "Column3"})

in

ReorderedColumns


In this example, we have a table with four columns, and we want to reorder them based on our preferences. We start by creating a Source table with the initial column order. We then apply the Table.ReorderColumns function to the Source table, specifying the new column order we want. The result is a new table with the columns reordered as per our preferences.

How to Use Table.ReorderColumns

Using Table.ReorderColumns is quite simple. Here’s how to use it:

1. Open Microsoft Excel and go to the Power Query Editor.

2. Load the data source you want to manipulate.

3. Select the table you want to reorder columns in.

4. Click on the “Transform Data” button to open the Power Query Editor.

5. In the Power Query Editor, select the “Reorder Columns” button from the “Transform” tab. Alternatively, you can use the “Table.ReorderColumns” function directly in the formula bar.

6. Specify the new column order you want.

Once you’ve specified the new column order, Power Query will automatically apply the changes to your table.

Tips for Using Table.ReorderColumns

Using Table.ReorderColumns is relatively straightforward, but here are some tips to help you make the most of this function:

– Always make a backup of your data before making any changes. This will ensure that you can revert back to the original data if something goes wrong.

– Make sure that the new column order makes sense. Reordering columns can be useful, but it can also make your data harder to understand if not done correctly.

– Use Table.ReorderColumns in combination with other Power Query functions to manipulate your data in more complex ways.

Table.ReorderColumns is an essential function in Power Query that allows users to customize the order of columns in a table based on their needs. Understanding the M code behind this function can help users make the most of its features and create more efficient data workflows. By following the tips outlined above, users can use Table.ReorderColumns to manipulate their data in more complex ways and gain a deeper understanding of their data.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)