dax

How can I display multiple selectedvalues in text?


I have code below but it prints out None when I select multiple or all the items in the filter.

How to get around with this?

enter image description here

DynamicTitle = 
"Selected Items: " & 
IF(
    ISBLANK(SELECTEDVALUE(TableName[ColumnName])),
    "None",
    CONCATENATEX(
        VALUES(TableName[ColumnName]), 
        TableName[ColumnName], 
        ", "
    )
)

Solution

  • DynamicTitle = 
    VAR SelectedItems = 
        CONCATENATEX(
            VALUES(TableName[ColumnName]), 
            TableName[ColumnName], 
            ", "
        )
    
    RETURN 
    "Selected Items: " & 
    IF(
        ISBLANK(SelectedItems),
        "None",
        SelectedItems
    )
    
    1. VALUES(TableName[ColumnName]) returns the distinct values currently selected.

    2. CONCATENATEX() joins them into a comma-separated string.

    3. ISBLANK(SelectedItems) handles the case when no values are selected, not when multiple are selected.

    4. This way, if 1 or many items are selected, they'll be listed. If none are selected, it returns "None".