Table.Transpose

D

T

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

In this article, we will explore the M code behind the Table.Transpose function and learn how it works.

What is the Table.Transpose function?

The Table.Transpose function is a built-in function in Power Query that allows you to transpose a table. Transposing a table means that you switch the rows and columns, so that the rows become columns and the columns become rows.

For example, if you have a table with three columns and four rows, transposing the table will create a new table with four columns and three rows.

How to use the Table.Transpose function

Using the Table.Transpose function is simple. You can either use the graphical user interface (GUI) or write the M code directly.

To use the GUI, follow these steps:

1. Select the table you want to transpose.

2. Go to the Transform tab and click on the Transpose button.

3. A new table will be created with the rows and columns transposed.

To write the M code directly, you can use the following code:


= Table.Transpose(#"Previous Step")


Replace “Previous Step” with the name of the previous step in your query. This code will create a new step in your query that transposes the table.

The M code behind the Table.Transpose function

The M code behind the Table.Transpose function is relatively simple. When you use the Table.Transpose function, Power Query generates the following M code:


let

Source = ,

TransposedTable = Table.Transpose(Source)

in

TransposedTable


The M code starts with the “let” statement, which defines the variables used in the query. The “Source” variable refers to the table you want to transpose.

The next line of code uses the Table.Transpose function to create a new table with the rows and columns transposed. The result of this function is stored in the “TransposedTable” variable.

Finally, the M code ends with the “in” statement, which tells Power Query to output the “TransposedTable” variable as the final result of the query.

The Table.Transpose function is a powerful tool that can be incredibly useful when working with data that needs to be pivoted or rotated. Understanding the M code behind this function can help you to use it more effectively and troubleshoot any issues that may arise.

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)