Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
barragan82
Helper II
Helper II

Populate Data Into a Text Box

Hello,

Is there a way to create a measure that will populate data in a text box? 

  1. I would like each result to be separated by a comma.
  2. I would like to include the word “and” before the last result.

Below is an example of what I am trying to accomplish. I would like the data from the Assignment Type column to automatically populate after the word “are” and include the word "and" before "Short Written Response" (the last result). Thank you for any help!

barragan82_0-1757696858728.pngbarragan82_3-1757696894007.png

 

2 ACCEPTED SOLUTIONS
MasonMA
Super User
Super User

@barragan82 

 

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)
        ) & "."
)

 

MasonMA_0-1757698219438.png

 

View solution in original post

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 )
        & "."
)

 

View solution in original post

6 REPLIES 6
MasonMA
Super User
Super User

@barragan82 

 

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)
        ) & "."
)

 

MasonMA_0-1757698219438.png

 

@MasonMA , you really are a rockstar! This is excactly what I needed. You rock! Many thanks. 

Happy to see this works for you:) 

Is there a way to modify this measure so that it doesn't include blank entries? At the moment, I"m getting a space and a comma for blank entries (ex.  , India, UK, and USA). Thanks again for all your help!

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 )
        & "."
)

 

This is great! Huge help! Thanks again!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.