Text Concatenation Operator & in DAX
In this article, we will learn how to use the text concatenation operator (&) in DAX to combine values from different columns and create a single text expression. We will also understand how ADDCOLUMNS can be used to display the combined result.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Is the Text Concatenation Operator in DAX?
The & operator is used to join text values together. It can combine text literals, column values, and expressions into a single text result.
For example, if we have a customer key of 101 and a customer name of John, we can combine them into:
101 - John
The & operator joins the values, while the text ” – “ adds a separator between them.
The & operator is used for text concatenation in DAX. It combines multiple values into a single text expression.
1. Retrieving the Customer Table
Query
EVALUATE
Customer
Step-by-step explanation
Step 1: EVALUATE
EVALUATE is used to return the result of a table expression.
Step 2: Customer
Customer is the table expression. Since we are specifying the table directly, DAX returns the table.
What will you get?
The result contains the columns and rows available in the Customer table.
| CustomerKey | Customer | Country-Region |
|---|---|---|
| 101 | John | Australia |
| 102 | Mary | United States |
| 103 | David | Canada |
The example above is for illustration. Your actual result will contain the data available in your Customer table.
EVALUATE Customer returns the complete Customer table.
2. Creating Customer Information Using Text Concatenation
Query
EVALUATE
ADDCOLUMNS(
Customer,
"Customer Info", Customer[CustomerKey] & " - " & Customer[Customer]
)
Step-by-step explanation
Step 1: EVALUATE
EVALUATE returns the result of the table expression.
Step 2: ADDCOLUMNS
ADDCOLUMNS creates a new column in the table expression. It keeps the existing columns and adds the new column we specify.
Step 3: Customer
This is the source table from which we want to retrieve the customer information.
Step 4: “Customer Info”
This is the name of the new column that will be created in the result.
Step 5: Customer[CustomerKey]
This retrieves the customer key value from the current row.
Step 6: & ” – “
The & operator joins the customer key with the text separator ” – “.
Step 7: & Customer[Customer]
The second & operator joins the separator with the customer name.
The complete expression:
Customer[CustomerKey] & " - " & Customer[Customer]
combines the customer key, separator, and customer name into one text value.
Understanding the Expression
| Expression Part | Purpose | Example Result |
|---|---|---|
| Customer[CustomerKey] | Retrieves the customer key | 101 |
| ” – “ | Adds a separator | – |
| Customer[Customer] | Retrieves the customer name | John |
| & | Combines the values | 101 – John |
What will you get?
The result contains all the existing columns from the Customer table, along with the newly created Customer Info column.
| CustomerKey | Customer | Country-Region | Customer Info |
|---|---|---|---|
| 101 | John | Australia | 101 – John |
| 102 | Mary | United States | 102 – Mary |
| 103 | David | Canada | 103 – David |
The example above is for illustration. Your actual result will contain the data available in your Customer table.
ADDCOLUMNS creates a new column, and the & operator combines the values into a single text expression.
3. How the Concatenation Works Row by Row
The expression is evaluated for each row of the Customer table.
| CustomerKey | Customer | First Value | Separator | Second Value | Final Result |
|---|---|---|---|---|---|
| 101 | John | 101 | – | John | 101 – John |
| 102 | Mary | 102 | – | Mary | 102 – Mary |
| 103 | David | 103 | – | David | 103 – David |
For example, when the current row contains 101 and John, the expression produces:
101 & " - " & "John"
Result: 101 - John
The same expression is evaluated for every row, producing a different concatenated result based on the values in that row.
Important Notes
1. The & operator combines values
The & operator joins text values and expressions into a single text result.
2. Text literals must be enclosed in double quotes
In the query, ” – “ is a text literal. Double quotes are used to define text values.
3. ADDCOLUMNS creates a new column
The Customer Info column is added to the result of the Customer table expression.
4. The original table is not modified
ADDCOLUMNS returns a new table expression for the query result. It does not modify the original Customer table.
5. The separator is optional
You can concatenate values without a separator, or use a different separator depending on the required output.
Customer[CustomerKey] & Customer[Customer]
Customer[CustomerKey] & " | " & Customer[Customer]
Practice Exercise
📝 Try This Query
Write a DAX query to create a new column named Customer Location by combining the Customer and Country-Region columns.
Use the following format:
John - Australia
Expected Query
EVALUATE
ADDCOLUMNS(
Customer,
"Customer Location", Customer[Customer] & " - " & Customer[Country-Region]
)
Conclusion
In this article, we learned how to use the text concatenation operator (&) in DAX.
- The & operator combines text values and expressions.
- ADDCOLUMNS creates a new column in the table expression.
- Text literals such as ” – “ can be used as separators.
- The concatenation expression is evaluated for each row.
- We can create useful text columns such as Customer Info and Customer Location.
Text concatenation is useful when you want to combine multiple pieces of information into a single readable value, such as customer identifiers, product descriptions, or location details.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist