Type.Union

D

T

The M Code Behind the Power Query M function Type.Union

One of the functions in Power Query that is commonly used for data transformation is the Type.Union function. The Type.Union function is used to combine tables with the same schema into a single table. In this article, we will explore the M code behind the Type.Union function and how it can be used to transform data.

Understanding Type.Union

The Type.Union function is used to combine tables with the same schema into a single table. It is a powerful function that can be used to transform and reshape data. The Type.Union function takes two or more tables as input and returns a single table that contains all the columns from the input tables.

The input tables must have the same schema, which means that they must have the same columns with the same data types. If the input tables have different schemas, the Type.Union function will return an error.

Here is the basic syntax for the Type.Union function:


Type.Union(table1, table2, ..., tableN)


In this syntax, `table1`, `table2`, and `tableN` are the input tables that will be combined into a single table.

The M Code Behind Type.Union

The M code behind the Type.Union function is relatively straightforward. The function simply combines the input tables into a single table by appending the rows of each table to the output table.

Here is the M code behind the Type.Union function:


let

Source = Type.Union(table1, table2, ..., tableN)

in

Source


In this code, `table1`, `table2`, and `tableN` are the input tables that will be combined into a single table. The `Type.Union` function is used to combine the tables, and the results are stored in the `Source` variable.

Using Type.Union in Power Query

Using the Type.Union function in Power Query is relatively easy. Here are the steps to use the Type.Union function in Power Query:

1. Open Power Query Editor.

2. Import the tables that you want to combine.

3. Select the first table that you want to combine.

4. Click on the “Add Column” tab.

5. Click on “Custom Column.”

6. In the “Custom Column” dialog box, enter the following formula:


Type.Union([Table1], [Table2], ..., [TableN])


7. Click “Ok” to create the custom column.

8. Repeat steps 3-7 for each table that you want to combine.

9. Click on “Close & Apply” to apply the changes.

Once you have applied the changes, Power Query will combine the tables into a single table using the Type.Union function.

The Type.Union function is a powerful function in Power Query that can be used to combine tables with the same schema into a single table. The M code behind the Type.Union function is relatively straightforward, making it easy for users to understand and modify the function as needed.

By using the Type.Union function in Power Query, users can transform and reshape data with ease, making it easier to analyze and draw insights from data. With its ease of use and powerful capabilities, the Type.Union function is a valuable tool for any user working with data in Power Query.

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)