powerbidaxssasssas-tabular

Filtering data in SSAS based on "AND", not "OR"


enter image description here

In SSAS I have this simple scheme with a list of partners with their tags and the directory of tags. With this scheme, filtering by tags works on the principle "OR" - one of the tags selected by user in the directory can be present for a partner - the partner will be selected.

And how to do this: all selected tags (principle "AND") from the directory of tags must be present for a partner in the partner table and only in this case the partner will be selected.


Solution

  • Create a measure similar to this one:

    FlagSlicerAND = 
      var slicerCount = IF(ISFILTERED(Tags[Tag]), COUNTROWS(ALLSELECTED('Tags')), 0)
      var partnerTagCount = DISTINCTCOUNT(Partners[TagId])
    
      return IF(slicerCount = 0 || slicerCount = partnerTagCount, 1, BLANK())
    

    You can then either add this measure as a Visual Filter and set it to is not blank, and/or use it in your other measures within, eg:

    Total Partners = 
      SUMX(
        DISTINCT(Partners[PartnerId]),
        [FlagSlicerAND]
      )