Text.Combine is a Power Query M function that combines a list of text values into a single text value. The function returns the combined text value, with an optional separator that can be specified for use in the final combined text.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Text.Combine(
texts as list,
optional separator as nullable text,
) as text
Argument | Attribute | Description |
---|---|---|
Texts | Text values provided within a list. | |
Separator | Optional | Provide separator as text value. |
Description
Returns the result of combining the list of text values, texts
, into a single text value. The function requires a list of text values (referred to as ‘texts’) to be combined. It also offers the option to define a ‘separator’, which, if provided, is inserted between each text value in the final output. This ‘separator’ can also be a null value, as denoted by ‘nullable’ in the syntax.
Examples
To better understand how the Text.Combine function works, let’s dive into a few illustrative examples.
Basic Example: Merging Text Values
Consider two text values: “Riverdale” and “12345”. We want to merge these into a single string. Here’s how you would use the Text.Combine
function:
Text.Combine( {"Riverdale", "12345"} ) // Returns "Riverdale12345"
In this instance, the function merges “Riverdale” and “12345” to create “Riverdale12345”.
Example with a Separator
The Text.Combine
function also allows you to define a separator for the combined text. For example, if you want to combine a list of brand names, each separated by a comma and a space, you can do this:
// Output: "Vyro, Zynk, Kixx, Cygn, Nylo"
Text.Combine( { "Vyro", "Zynk", "Kixx", "Cygn", "Nylo" }, ", " )
This returns “Vyro, Zynk, Kixx, Cygn, Nylo”, a single string with each brand separated by a comma and a space. One advantage is that you can replace the above list of text values with a reference to a table column.
Manual Method Comparison
Compare this to the manual method of combining text:
"Vyro" & ", " & "Zynk" & ", " & "Kixx" & ", " & "Cygn" & ", " & "Nylo"
The manual method is more verbose, especially for long lists. Additionally, you cannot easily incorporate values from a table column using this method.
Handling Null Values
One unique aspect of Text.Combine
is its handling of null values. Unlike the manual method of combining text values with operators, Text.Combine
ignores any null values it encounters:
Text.Combine( {"a", null, "c", null, "e" }, ", " ) // Output: "a, c, e"
This is in contrast to the manual method, where the entire output becomes null if a null value is encountered in the combination:
"a" & null & "c" & null & "e" // Output: null
The Text.Combine
function in Power Query M language offers an effective way to merge text values, even when they include null values. Its ability to handle separators and null values efficiently makes it a useful tool for dealing with values.
Related articles
Learn more about Text.Combine in the following articles:
- Concatenate Values in Power Query
Learn how to Concatenate Values with Power Query. Find out how to handle delimiters, data types, and conditions like a pro. » Read more - Pivot Text Values in Power Query – Explained
What is the Pivot Columns operation in Power Query? And how can you use it to pivot text values and numbers? Follow along to find out! » Read more - Replace Values in Power Query M (Ultimate Guide)
Learn how to replace values in Power Query. Look into conditional replacements, replacing in multiple columns, case sensitivity and more! » Read more - Concatenate Text with Group By (Combine Rows) in Power Query
In this post you learn how to use group by to concatenate text values. It allows you to summarize the data in a comma separated list. » Read more - Text Functions in Power Query M (150+ Examples)
Your guide to Text Functions in Power Query M. Learn from practical examples and master Power Query’s most useful Text functions. » Read more
Related functions
Other functions related to Text.Combine are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy