Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a Slicer, i.e.
I want to write a logic DAX function using IF() like:
Singe
In the multiple selections
How to write the DAX function to identify whether or not "Successful" is selected?
Solved! Go to Solution.
@Anonymous ,
You may create a measure using dax below:
Result = IF(CONTAINSSTRINGEXACT(CONCATENATEX(ALLSELECTED('Table'), 'Table'[project_status], ""), "Successful") = TRUE(), "A", "B")
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymous
I see @v-yuta-msft has provided a solution (I wasn't even aware of the function CONTAINSSTRINGEXACT!)
Just as an alternative, I worked on a different approach:
Proud to be a Super User!
Paul on Linkedin.
Here is simpler one: it works if we have to keep a check if any option is selected, If nothing selected or selected both case need to be worked, then remove Is filtered and use if satetment.
To make sure Slicer is filtered:
@Anonymous ,
You may create a measure using dax below:
Result = IF(CONTAINSSTRINGEXACT(CONCATENATEX(ALLSELECTED('Table'), 'Table'[project_status], ""), "Successful") = TRUE(), "A", "B")
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Note that this method breaks if you have two rows in the slicer table that contain the same text, e.g.
"Sales"
and "Sales (adjusted)". When "Sales (adjusted)" is selected in the slicer, the code with think that the "Sales" option was selected, when it wasn't.
Result = IF(CONTAINSSTRINGEXACT(CONCATENATEX(ALLSELECTED('Table'), 'Table'[project_status], ""), "Sales") = TRUE(), "A", "B")
The COUNTROWS method that @PaulDBrown posted might be more robust.
@Anonymous
you can use SELECTEDVALUE in your measure. For example:
measure = IF(SELECTEDVALUE(table[project_status]) = “Successful”, [measure 1], [measure 2])
Proud to be a Super User!
Paul on Linkedin.
Thank you.
But it only works for a single selection. If I select multiple values including "Successful", it can't work...
@Anonymous
I see @v-yuta-msft has provided a solution (I wasn't even aware of the function CONTAINSSTRINGEXACT!)
Just as an alternative, I worked on a different approach:
Proud to be a Super User!
Paul on Linkedin.
Thanks.
In my case, need to change the last line into: if(calc>=1,"YES","NO")
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
76 | |
74 | |
57 | |
38 | |
33 |
User | Count |
---|---|
71 | |
66 | |
57 | |
49 | |
47 |