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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
AlexF_HH
Frequent Visitor

Conditional filtering?

Hi Community,

 

i guess i have a beginner question here.
Please take a look at this simple table:

 

2020-04-28_1603

 
 

My taks is to qount the unique items in 'Column1' that equal X but NOT Y in 'Column 2'.
The result shoub be 'B' -> 1.

Normal Filtering doesn't work for that kind of problems.
The best formula i was able to build was:

Measure  = CALCULATE(DISTINCTCOUNT(Tabelle1[Column1]);Tabelle1[Column2] = "X" && Tabelle1[Column2] <> "Y")


But that formula returns A, B -> 2

Maybe you can suggest a nice solution for that.

It would be great if the logic also works with mutiple factors like: Count uniques items WHERE Column2 IS 'X' BUT NOT 'Y'  AND Column3 IS 'Z' BUT NOT 'W' etc..

Thank you!

Alex 

1 ACCEPTED SOLUTION

Hi @AlexF_HH ,

 

Using measure returns only one aggregate value, not one row. But you can add a calculated table for it or add a filter in table visual.

 

Here is the dax for calculated table:

 

Table 2 =

VAR a =

    SUMMARIZE (

        'Table1',

        'Table1'[Column1],

        "ifcontainY", IF (

            "Y" IN VALUES ( 'Table1'[Column2] ),

            0,

            CALCULATE (

                DISTINCTCOUNT ( 'Table1'[Column1] ),

                FILTER ( 'Table1', 'Table1'[Column2] <> "Y" )

            )

        )

    )

RETURN

    FILTER ( a, [ifcontainY] <> 0 )

 

>>Count unique items in Column1 having Column 2 = X but NOT = Y AND Column3 = "yes" but NOT = "no".

 

Please refer to:

 

Table =

VAR a =

    SUMMARIZE (

        'Table1',

        'Table1'[Column1],

        "ifcontainY", IF (

            "Y" IN VALUES ( 'Table1'[Column2] )

                && "no" IN VALUES ( 'Table1'[Column3] ),

            0,

            CALCULATE (

                DISTINCTCOUNT ( 'Table1'[Column1] ),

                FILTER ( 'Table1', 'Table1'[Column2] <> "Y" && Table1[Column3] <> "no" )

            )

        )

    )

RETURN

    FILTER ( a, [ifcontainY] <> 0 )

 

Untitled picture2.png

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

 

Best Regards,

Dedmon Dai

View solution in original post

4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @AlexF_HH ,

 

Would you please tell me if the screenshot below is your expected output? Or you can show us your expected output?

Untitled picture.png

You can create a measure like:

 

Measure =

IF (

    "Y" IN VALUES ( 'Table'[Column2] ),

    0,

    CALCULATE (

        DISTINCTCOUNT ( 'Table'[Column1] ),

        FILTER ( 'Table', 'Table'[Column2] <> "Y" )

    )

)

 

If you want the logic also work with multiple factors, the measure really need to be modified depend on your requirement.

 

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

 

Best Regards,

Dedmon Dai

Hi @v-deddai1-msft ,

 

thank you for your feedback.

 

i just expected the total in your output to be 1.

B is the only item that has a Column2 relation = X and NO relations = Y.
So that part is correct: 

 

2020-04-29_0948

 

By multiple factors i mean the same kind of logic but used multiple times.

2020-04-29_0950

Count unique items in Column1 having Column 2 = X but NOT = Y AND Column3 = "yes" but NOT = "no".
The expecxted Measure  output would be B -> 1.

Thank you

Alex

Hi @AlexF_HH ,

 

Using measure returns only one aggregate value, not one row. But you can add a calculated table for it or add a filter in table visual.

 

Here is the dax for calculated table:

 

Table 2 =

VAR a =

    SUMMARIZE (

        'Table1',

        'Table1'[Column1],

        "ifcontainY", IF (

            "Y" IN VALUES ( 'Table1'[Column2] ),

            0,

            CALCULATE (

                DISTINCTCOUNT ( 'Table1'[Column1] ),

                FILTER ( 'Table1', 'Table1'[Column2] <> "Y" )

            )

        )

    )

RETURN

    FILTER ( a, [ifcontainY] <> 0 )

 

>>Count unique items in Column1 having Column 2 = X but NOT = Y AND Column3 = "yes" but NOT = "no".

 

Please refer to:

 

Table =

VAR a =

    SUMMARIZE (

        'Table1',

        'Table1'[Column1],

        "ifcontainY", IF (

            "Y" IN VALUES ( 'Table1'[Column2] )

                && "no" IN VALUES ( 'Table1'[Column3] ),

            0,

            CALCULATE (

                DISTINCTCOUNT ( 'Table1'[Column1] ),

                FILTER ( 'Table1', 'Table1'[Column2] <> "Y" && Table1[Column3] <> "no" )

            )

        )

    )

RETURN

    FILTER ( a, [ifcontainY] <> 0 )

 

Untitled picture2.png

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

 

Best Regards,

Dedmon Dai

Hi @v-deddai1-msft ,

 

thank you very much!

 

Best Regards

 

Alex

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors