Forum Discussion

MG06's avatar
MG06
Regular Visitor
3 years ago
Solved

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:

 

MockupTest
      Name                Primary Skills                 Secondary Skills          
IrinaA, B, CG, H, I, E
AmyD, E, FI, C, H
BobD, 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_metric
    Skills     
A
B
C...
 
Inside this table, I created a metric with this code:

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         
IrinaA, B, CG, H, I, E
BobD, B, C

A, E

 

 
  • Anonymous's avatar
    Anonymous
    3 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

  • Anonymous's avatar
    Anonymous
    Not 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.

     

     

    • MG06's avatar
      MG06
      Regular Visitor

      This worked perfectly!! Thank you 😄