Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
venkatnitt84
Frequent Visitor

Filter with And Condition using slicer

I have a requirement where i need to filter the data based on the selected Value using "AND" condition.

Below is an example for the requirement.

 

If user selects "ABC" and "DEF" value , only District "A" and District "C" should be displayed.

District "B" should not be displayed as it doesnot have Value "DEF".

Basically i need to make sure all selected value is checked instead just one value for the given level.

Let me know if any one have achieved using DAX or any other method.

 

DistrictOptionAmt  Slicer Selection 
AABC1000  ABC
ADEF1000  DEF
AKKK1000  KKK
BABC1000  ZZZZ
BZZZZ1000  EEEE
BEEEE1000  MMM
CABC1000   
CDEF1000   
CMMM1000   
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @venkatnitt84 ,

You can follow the below steps to achieve it:

1. Create a measure as below

Include all selections? = 
VAR _sel =
    ALLSELECTED ( 'Table'[Option] )
VAR _countofOp =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Option] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[District] = MAX ( 'Table'[District] )
                && 'Table'[Option] IN _sel
        )
    )
VAR _district =
    CALCULATE (
        MAX ( 'Table'[District] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[District] = MAX ( 'Table'[District] )
                && 'Table'[Option] IN _sel
        )
    )
RETURN
    IF ( COUNTROWS ( _sel ) = _countofOp, 1, 0 )

2. Then create a table with District field and add filter with new created measure=1

Filter with And Condition using slicer.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @venkatnitt84 ,

You can follow the below steps to achieve it:

1. Create a measure as below

Include all selections? = 
VAR _sel =
    ALLSELECTED ( 'Table'[Option] )
VAR _countofOp =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Option] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[District] = MAX ( 'Table'[District] )
                && 'Table'[Option] IN _sel
        )
    )
VAR _district =
    CALCULATE (
        MAX ( 'Table'[District] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[District] = MAX ( 'Table'[District] )
                && 'Table'[Option] IN _sel
        )
    )
RETURN
    IF ( COUNTROWS ( _sel ) = _countofOp, 1, 0 )

2. Then create a table with District field and add filter with new created measure=1

Filter with And Condition using slicer.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yiruan-msft ,

 

Thank you for your solution. I was doing something similar and yours helped me. But there is one issue in my case as my data model is like this, 

jagan2678_0-1667286541757.png

 

 

Include all selections for office? =
VAR _selected =
    ALLSELECTED ( 'dim'[year] )
VAR _options =
    CALCULATE (
        DISTINCTCOUNT ( 'office'[year]  ),
        FILTER (
            ALLSELECTED ( 'office' ),
            'office'[office] = MAX ( 'office'[office] )
                && 'office'[year] IN _sel
        )
    )
 
RETURN
    IF ( COUNTROWS ( _selected ) = _options, 1, 0 )

 

So here the above measure which i created based on urs, is working for the table with active realtionship i.e year column of office table is in active relation with year column of dimdate.

 

But, when i try to do the same for the another table hotel which has an inactive relationship, i dont get the results,

 

Include all selections for hotel? =
VAR _selected =
    ALLSELECTED ( 'dim'[year] )
VAR _options =
    CALCULATE (
        DISTINCTCOUNT ( 'hotel'[year]  ),
        FILTER (
            ALLSELECTED ( 'hotel' ),
            'hotel'[hotel] = MAX ( 'hotel'[hotel] )
                && 'hotel'[year] IN _sel
        )
    )
 
RETURN
    IF ( COUNTROWS ( _selected ) = _options, 1, 0 )

 

help me with this. i was like trying to use the userelationship function,, but i dont know where to use this function in the above measure.

 

Thanks in advance

amitchandak
Super User
Super User

@venkatnitt84 , Try new measures like

 

measure =
var _cnt = count(allselected(Table), Table[District])
return
countX(filter(summarize(Table, Table[District], "_1", count(Table[District]), "_2", sum(Table[Amit])), [_1]>=_cnt),[District])

Amount =
var _cnt = count(allselected(Table), Table[District])
return
countX(filter(summarize(Table, Table[District], "_1", count(Table[District]), "_2", sum(Table[Amit])), [_1]>=_cnt),[_2])

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.