DAX – Concatenating Values only when values are selected
What I am doing with the DAX below is to only show the concatenation of values if a value is filtered. If nothing is filtered (Selected) then display text to show that nothing has been selected, otherwise display in a concatenation what has been selected.
NOTE: If you individually have to select each item, it is still being filtered so it will show all the values concatenated.
Selected User = VAR ConCat = CALCULATE ( CONCATENATEX ( VALUES ( 'Power BI Audit Log'[User] ), 'Power BI Audit Log'[User], "," ) ) VAR IsItFiltered = IF ( ISFILTERED ( 'Power BI Audit Log'[User] ), ConCat, "No Users Selected" ) RETURN IsItFiltered
- What is happening above with the Variable called “ConCat” is where I am concatenating the items from the ‘PowerBI Audit Log’ table and using the [User] column.
-
Then in the next Variable called “IsItFiltered” I am using the IF and ISFILTERED DAX function to evaluate if the [User] column is being filtered.
- If it is being filtered then return the previous Variable called “ConCat” otherwise return “No Users Selected”
- And the final piece is where I am returning the output from the IsItFiltered Variable
-
This is what it looks like when No users are selected
-
And then when two users are selected
As always if there are any questions please leave them in the comments below.
Thanks. How do you change the concatenatex formula so that concatenate number in the order you selected them. I’m selecting 5 then 1 then 4, but concatenatex returns 145 – thus sorting the selected values.
Can you please assist?
Hi there
As far as I am aware currently it appears to sort it by the number value.
What happens if you change it from Number to Text and try sorting?
Yes I have a same scenario, I have a sequence column, Name column. I sorted the name column based on sequence in Modelling tab. When I am selecting multiple Names from slicer and concatenating it in measure, It is randomly taking selected names for concatenation though the names appear in the slicer is sorted based on Sequence.
DAX query:
selectedones =
VAR ConCat =
CALCULATE (
CONCATENATEX (
VALUES (milestoneindex[MilestoneName]),
milestoneindex[MilestoneName],
“-”
)
)
VAR notselected=
CALCULATE (
CONCATENATEX (
ALL (milestoneindex[MilestoneName]),
milestoneindex[MilestoneName],
“-”
)
)
VAR IsItFiltered =
IF ( ISFILTERED (milestoneindex[MilestoneName]), ConCat, notselected )
RETURN
IsItFiltered
I found it!
CONCATENATEX(Table, Expression, [Delimiter], [OrderBy_Expression1], [Order1], …)
New DAX-
selectedones =
VAR ConCat =
CALCULATE (
–concatenate(
CONCATENATEX (
VALUES (milestoneindex),
milestoneindex[MilestoneName],
“-“,
milestoneindex[MilestoneSequence],ASC
)
–,”,”)
)
VAR notselected=
CALCULATE (
–concatenate(
CONCATENATEX (
ALL (milestoneindex),
milestoneindex[MilestoneName],
“-“,
milestoneindex[MilestoneSequence],ASC
)
–,”,”)
)
VAR IsItFiltered =
IF ( ISFILTERED (milestoneindex[MilestoneName]), ConCat, notselected )
RETURN
IsItFiltered
That looks good, congrats and getting it right, and I appreciate posting the solution too.
How do I extend this to have multiple columns? For instance, I have 4 fields(columns), year, quarter, month, day. How do I concat all 4 columns (same table)?
Hi there
Do you want the 4 fields to have multiple values, or to select 4 different fields together?
Hello
What if I have 100 values and in case all are selected, I want to show “multiple values selected”.
As today, ISFILTERED doesn’t understand the difference between all values selected and no values selected”, so I am not able to write DAX for this.
Any ideas?
Regards
Hi there, what you could do, is to put in another variable with the following which should work
VAR AllSelectedItems = SELECTEDVALUE(IsItFiltered,”Multiple Values Selected”)
RETURN
AllSelectedItems
Excellent solution! Thanks for sharing your wisdom!
Always happy to help!
Hi Gilbert,
Can you please answer @diskovered question.
Hi there
I am still waiting for an answer to the question I asked before I can answer
Hello,
Can you answer for; concat multiple columns into 1 column
Depending on what is selected in the filter.
E.g.
Slicer has Column 1, Column 4, Column 5 selected.
Concat Column would show, Column1Column4Column5
It would often depend on a single column as far as I am aware.
Hi!
I am searching for a solution where the last value have an &-sign instead of a comma. It is maybe very detailed but I prefer that way 🙂
Let me know if you have any ideas. (For some additional background, I am working with a report that has revenue from 10 brands and I want a title, showing what slicers are selected and this is the only part missing)
Hope you still see this comment.
Hi there
This blog post might be what you are looking for to get it showing the values
https://sqldusty.com/2016/06/29/5-more-power-bi-tips/
Hi !
Can you please give solutions for both : if I want the 4 fields to have multiple values, or to select 4 different fields together?
Hi there,
Thanks for the comment.
This will work on a single column in a table, where multiple items are selected.
If you want to do it for multiple fields, you would need to create a variable for each table/column.
And then finally you would then have to combine the results together.
Thank you for posting this solution Gilbert!
Happy to help Peter!