Record.Combine

D

T

The M Code Behind the Power Query M function Record.Combine

Understanding the Record.Combine Function

The Record.Combine function is used to combine two or more records into one. It takes two or more records as input and returns a new record that contains all the fields from the input records. The function combines records based on their field names. If there are duplicate fields, the function keeps the value from the last record.

The syntax for the Record.Combine function is as follows:


Record.Combine(record1 as record, record2 as record, …) as record


Where `record1`, `record2`, and so on, are the records that you want to combine.

How Record.Combine Works

To understand how Record.Combine works, let's take a look at an example. Suppose we have the following two records:


Record1:

{

“Name”: “John”,

“Age”: 30,

“City”: “New York”

}

Record2:

{

“Name”: “Jane”,

“Gender”: “Female”

}


If we apply the Record.Combine function to these two records, the result would be:


{

“Name”: “Jane”,

“Age”: 30,

“City”: “New York”,

“Gender”: “Female”

}


As you can see, the fields from both records are combined into a new record. The value for the "Name" field is taken from the second record since it appears last. The values for the other fields are taken from the first record.

How to Use Record.Combine in Power Query

To use the Record.Combine function in Power Query, you need to follow these steps:

1. Open the Power Query Editor by clicking on the "Edit Queries" button in the "Home" tab.

2. Load the data that you want to combine into records.

3. Create a new query by clicking on the "New Source" button in the "Home" tab.

4. In the "New Source" dialog box, select "Blank Query" and click on the "OK" button.

5. In the new query, create a new record by using the curly braces {} and the field names and values separated by colons.

6. Repeat step 5 for each record that you want to combine.

7. Use the Record.Combine function to combine the records. You can do this by typing the function name and the records as arguments separated by commas.

8. Load the combined records into a new table by right-clicking on the query and selecting "Close & Load To".

The Record.Combine function in Power Query allows you to combine two or more records into one. It is a useful feature that can save you a lot of time and effort when working with data. By understanding the M code behind the function, you can use it effectively in your Power Query workflows.

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)