CONCATENATEX in DAX: lists of selected values as text

How CONCATENATEX joins values from a table into one text in DAX, the selected slicer values in a title, top products as a sentence, delimiters and line breaks, sort order (descending by default), limits for long lists, and CONCATENATE and the & operator.

Short answer: CONCATENATEX ( table, expression [, delimiter [, orderBy, order ]] ) evaluates the expression for each row of a table and joins the results into one text: CONCATENATEX ( VALUES ( Customer[Country] ), Customer[Country], ", " ) returns "Austria, Germany, Switzerland". It is the way to show which values are selected in a title, to list the top products in a sentence, or to build a tooltip line. For two pieces of text, use the & operator.

A slicer shows its selection only while it is on the page. Exported, printed or in a subscription email, the reader no longer knows what was filtered. A line built with CONCATENATEX carries the selection into the title.

How do you show the selected values?

Selected Countries =
VAR N = COUNTROWS ( VALUES ( Customer[Country] ) )
VAR Total = COUNTROWS ( ALL ( Customer[Country] ) )
RETURN
    SWITCH (
        TRUE (),
        NOT ISFILTERED ( Customer[Country] ), "All countries",
        N > 3, N & " of " & Total & " countries",
        CONCATENATEX ( VALUES ( Customer[Country] ), Customer[Country], ", ", Customer[Country], ASC )
    )

Title = "Revenue by month, " & [Selected Countries]
Slicer selectionTitle
nothingRevenue by month, All countries
Austria, GermanyRevenue by month, Austria, Germany
7 countriesRevenue by month, 7 of 24 countries
What the title shows

Use it as a visual's title with Format, Title, fx, field value Title.

How do you list the top products?

Top 3 Products =
VAR T = TOPN ( 3, VALUES ( 'Product'[Product] ), [Revenue], DESC )
RETURN
    CONCATENATEX (
        T,
        'Product'[Product] & " (" & FORMAT ( [Revenue], "#,0" ) & ")",
        ", ",
        [Revenue], DESC
    )

Result: "Road-150 (1,200), Mountain-200 (900), Helmet (500)". TOPN picks the rows, CONCATENATEX writes them, and the orderBy keeps them in revenue order.

How do delimiters and order work?

ArgumentExampleNote
delimiter", " or " | "between items, not after the last
line breakUNICHAR ( 10 )each item on a new line in tooltips and cards with word wrap
orderByCustomer[Country] or [Revenue]evaluated per row
orderASC or DESCMicrosoft's default is DESC when omitted
CONCATENATEX arguments

Without an orderBy, the order is not defined; always give one if the order matters.

CONCATENATEX, CONCATENATE or &?

UseWhen
"a" & "b" & "c"joining a few known texts
CONCATENATE ( "a", "b" )exactly two texts; & is simpler
CONCATENATEX ( table, ... )a list from a table, any number of rows

What goes wrong?

  • Very long lists. Hundreds of values make unreadable titles and slow measures; show a count above a threshold, as above.
  • Duplicates. Iterating a fact table repeats values; iterate VALUES ( column ).
  • Missing order. Results come in an undefined order; pass orderBy and ASC.
  • Numbers without format. [Revenue] inside the text shows all decimals; wrap it in FORMAT.

Where can you check this?

Where do you start?

Add Selected Countries to the title of your main chart so exports and emails keep the filter. Text functions cover the rest of text work in DAX.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.