Forum Discussion
Help with DAX for slicers - multiple selections and default value
Hello everyone! Can you help me? I’m new to PowerBI
I have a table ("MockupTest") that has names and the primary/secondary skills of those people, something like this:
| Name | Primary Skills | Secondary Skills |
| Irina | A, B, C | G, H, I, E |
| Amy | D, E, F | I, C, H |
| Bob | D, B, C | A, E |
I'm trying to make a single slicer to filter both columns ("Primary Skills" and "Secondary Skills), where you can select each of the skills (for example, just "A" or "B"). Right now, I created a new table called "Skills_metric" where I added the column "Skills" and each row has only one skill, like:
| Skills |
| A |
| B |
| C... |
filterSkills = VAR a = IF (CONTAINSSTRING(VALUES ('MockupTest'[Primary Skills]), VALUES ('Skills_metric'[Skill]))
|| CONTAINSSTRING(VALUES ( 'MockupTest'[Secondary Skills] ), VALUES ( 'Skills_metric'[Skill])),
1, 0)
RETURN IF ( ISFILTERED ( 'Skills_metric'[Skill] ), a, 0 )
Then used the column "Skills" in the slicer and put the metric "filterSkills" inside the filters for the "MockupTest" table.
This is working fine with single selections but doesn't allow me to pick multiple selections in the slicer. Also, the default value is no row at all (just the headers appear if you don’t select any skill in the slicer).
Can someone correct my code or give me a new one? The expected result would be something like this:
Selected: "A" and "B"
| Name | Primary Skills | Secundary Skills |
| Irina | A, B, C | G, H, I, E |
| Bob | D, B, C | A, E |
- Anonymous3 years ago
Hi MG06
You can refer to the following measure
Measure = var a=COUNTROWS(FILTER(VALUES('Table (2)'[Skills]),CONTAINSSTRING(SELECTEDVALUE('Table'[Primary Skills]),[Skills]))) var b=COUNTROWS(FILTER(VALUES('Table (2)'[Skills]),CONTAINSSTRING(SELECTEDVALUE('Table'[Secondary Skills]),[Skills]))) return IF(OR(a>0,b>0),1,0)Then put the measure to the visual filter
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi MG06
You can refer to the following measure
Measure = var a=COUNTROWS(FILTER(VALUES('Table (2)'[Skills]),CONTAINSSTRING(SELECTEDVALUE('Table'[Primary Skills]),[Skills]))) var b=COUNTROWS(FILTER(VALUES('Table (2)'[Skills]),CONTAINSSTRING(SELECTEDVALUE('Table'[Secondary Skills]),[Skills]))) return IF(OR(a>0,b>0),1,0)Then put the measure to the visual filter
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- MG06Regular Visitor
This worked perfectly!! Thank you 😄