Forum Discussion
barragan82
11 months agoHelper II
Populate Data Into a Text Box
Hello, Is there a way to create a measure that will populate data in a text box? I would like each result to be separated by a comma. I would like to include the word “and” before the last resul...
- 11 months ago
Hi, try this sample code a DAX Measure. Replace Table and Column names with your actual ones, also replace the text part for Single item display and Multiple items display.
Text = VAR ItemsList = DISTINCT('Table'[Country]) VAR CountItems = COUNTROWS(ItemsList) VAR ConcatText = CONCATENATEX( ItemsList, 'Table'[Country], ", ", 'Table'[Country], ASC ) RETURN IF( CountItems = 1, "Country in Column is: " & MAX('Table'[Country]) & ".", "Countries in Column are " & SUBSTITUTE( ConcatText, ", " & LASTNONBLANK('Table'[Country], 1), ", and " & LASTNONBLANK('Table'[Country], 1) ) & "." ) - 11 months ago
You can tweak some more based on this sample code
Text = VAR ItemsList = FILTER( DISTINCT( 'Table'[Country] ), LEN( TRIM( COALESCE( 'Table'[Country], "" ) ) ) > 0 ) VAR CountItems = COUNTROWS( ItemsList ) VAR ConcatText = CONCATENATEX( ItemsList, TRIM( COALESCE( 'Table'[Country], "" ) ), " ", TRIM( COALESCE( 'Table'[Country], "" ) ), ASC ) VAR LastItem = MAXX( ItemsList, TRIM( COALESCE( 'Table'[Country], "" ) ) ) RETURN SWITCH( TRUE(), CountItems = 0, BLANK(), CountItems = 1, "Country in Column is " & LastItem & ".", "Countries in Column are " & SUBSTITUTE( ConcatText, " " & LastItem, " and " & LastItem ) & "." )
MasonMA
11 months agoSuper User
You can tweak some more based on this sample code
Text =
VAR ItemsList =
FILTER(
DISTINCT( 'Table'[Country] ),
LEN( TRIM( COALESCE( 'Table'[Country], "" ) ) ) > 0
)
VAR CountItems = COUNTROWS( ItemsList )
VAR ConcatText =
CONCATENATEX(
ItemsList,
TRIM( COALESCE( 'Table'[Country], "" ) ),
" ",
TRIM( COALESCE( 'Table'[Country], "" ) ),
ASC
)
VAR LastItem =
MAXX( ItemsList, TRIM( COALESCE( 'Table'[Country], "" ) ) )
RETURN
SWITCH(
TRUE(),
CountItems = 0, BLANK(),
CountItems = 1, "Country in Column is " & LastItem & ".",
"Countries in Column are " &
SUBSTITUTE( ConcatText, " " & LastItem, " and " & LastItem )
& "."
)
barragan82
11 months agoHelper II
This is great! Huge help! Thanks again!