Forum Discussion

MPetramalo214's avatar
4 years ago
Solved

Using two Distinct Count of fields in a matrix

I have a weird case that I've been racking my brain on and I just can't seem to figure this out.  Any help would be appreciated because I'm sure this is an easy solve that I'm just not thinking of. ...
  • v-xiaotang's avatar
    4 years ago

    Hi MPetramalo214 

    In this scenario, its essence is to count according to the combination of cat and dog. However, the matrix cannot combine people with different ids, so you need to create a measure. In matrix, measure cannot be put in Rows (see picture below). So it needs to create a dimension table first.

    (1) create a dimension table

    (2) create a measure

    Count of Owner IDs =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[owner_id] ),
        FILTER (
            ALL ( 'Table' ),
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER ( ALLEXCEPT ( 'Table', 'Table'[owner_id] ), 'Table'[species_id] = 1 )
            )
                = MIN ( 'dimension table'[Dog] )
                && CALCULATE (
                    COUNTROWS ( 'Table' ),
                    FILTER ( ALLEXCEPT ( 'Table', 'Table'[owner_id] ), 'Table'[species_id] = 2 )
                )
                    = MIN ( 'dimension table'[Cat] )
        )
    )

    result

    Best Regards,

    Community Support Team _Tang

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