Text.Combine

D

T

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

In this article, we will take a deep dive into the M code behind the Text.Combine function, exploring its syntax and capabilities, and providing examples of how it can be used to simplify data transformations in Power Query.

Syntax of the Text.Combine Function

The Text.Combine function is used to combine text values from multiple columns into a single column. It takes two arguments:


Text.Combine(list as list, optional separator as nullable text) as text


The first argument is a list of text values that need to be combined. The second argument is an optional separator that is used to separate the text values in the final output. If the separator argument is not specified, the default separator is a blank space.

Examples of Using the Text.Combine Function

Example 1 – Combining Two Columns

Suppose we have a table containing two columns – First Name and Last Name. We want to combine these two columns into a single column called Full Name. The M code to achieve this using the Text.Combine function is as follows:


= Table.AddColumn(Source, "Full Name", each Text.Combine({[First Name], [Last Name]}, " "))


In this example, the Text.Combine function is used to combine the values from the First Name and Last Name columns into a single column called Full Name. The curly braces { } are used to create a list of the text values that need to be combined. The separator argument (” “) is used to separate the First Name and Last Name values with a blank space.

Example 2 – Combining Multiple Columns

Suppose we have a table containing three columns – First Name, Middle Name, and Last Name. We want to combine these three columns into a single column called Full Name. The M code to achieve this using the Text.Combine function is as follows:


= Table.AddColumn(Source, "Full Name", each Text.Combine({[First Name], [Middle Name], [Last Name]}, " "))


In this example, the Text.Combine function is used to combine the values from the First Name, Middle Name, and Last Name columns into a single column called Full Name. The curly braces { } are used to create a list of the text values that need to be combined. The separator argument (” “) is used to separate the First Name, Middle Name, and Last Name values with a blank space.

Example 3 – Concatenating Text and Numeric Values

Suppose we have a table containing two columns – First Name and Age. We want to combine these two columns into a single column called Output that contains the text “My name is {First Name} and I am {Age} years old”. The M code to achieve this using the Text.Combine function is as follows:


= Table.AddColumn(Source, "Output", each Text.Combine({"My name is ", [First Name], " and I am ", Text.From([Age]), " years old"}, " "))


In this example, the Text.Combine function is used to concatenate the text values “My name is “, [First Name], ” and I am “, and the numeric value [Age], which is first converted to text using the Text.From function. The result is a single column called Output that contains the combined text value.

The Text.Combine function is a powerful tool for combining text values from multiple columns into a single column in Power Query. It can be used to simplify data transformations and make data analysis more efficient. By understanding the syntax and capabilities of the Text.Combine function, users can take full advantage of the power of Power Query and streamline their data analysis 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)