Forum Discussion

Titatovenaar2's avatar
Titatovenaar2
Icon for Advocate II rankAdvocate II
3 years ago
Solved

DAX Measure: Show ID's where Column B has multiple values for Column A

Hi,

 

I have a simple table like this:

IDCat1Cat2
1A01
2A02
3B01
4C01
5D01
6D01

 

I want to view the records where Cat1 has multiple values for Cat2.

Which should look like the following, because only for Cat1 A, Cat2 has multiple values.

IDCat1Cat2Measure
1A011
2A021
3B010
4C010
5D010
6D010

 

The following DAX shows the correct COUNT, but when placed in the above table, it shows BLANK values. It does not show 1's or 0's per row. This makes sense, because the measure is on the level of Cat1. How to change the DAX in a way to view 1's and 0's per row on the level of column 'ID'?

 

 

COUNTROWS(
    FILTER(
        ADDCOLUMNS(
            SUMMARIZE(
                'Table'
                ,'Table'[Cat1]
            )
            ,"CNT Cat2",CALCULATE(DISTINCTCOUNT('Table'[Cat2]))
        ),[CNT Cat2] > 1
    )
)

 

I need a measure instead of a calculated column in this model.

 

Does anyone have any suggestion how to tackle this?

Kind regards,

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    Expected outcome measure: =
    VAR _result =
        COUNTROWS (
            FILTER (
                ADDCOLUMNS (
                    DISTINCT ( 'Table'[Cat1] ),
                    "@count",
                        CALCULATE (
                            COUNTROWS ( DISTINCT ( 'Table'[Cat2] ) ),
                            ALL ( 'Table'[ID], 'Table'[Cat2] )
                        )
                ),
                [@count] > 1
            )
        ) > 0
    RETURN
        IF ( ISINSCOPE ( 'Table'[Cat1] ), DIVIDE ( _result, _result, 0 ) )
    

2 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

    Expected outcome measure: =
    VAR _result =
        COUNTROWS (
            FILTER (
                ADDCOLUMNS (
                    DISTINCT ( 'Table'[Cat1] ),
                    "@count",
                        CALCULATE (
                            COUNTROWS ( DISTINCT ( 'Table'[Cat2] ) ),
                            ALL ( 'Table'[ID], 'Table'[Cat2] )
                        )
                ),
                [@count] > 1
            )
        ) > 0
    RETURN
        IF ( ISINSCOPE ( 'Table'[Cat1] ), DIVIDE ( _result, _result, 0 ) )