Forum Discussion

Peterdown's avatar
Peterdown
Frequent Visitor
1 month ago
Solved

Counting distinct list against multiple contain strings

Looking for some assistance. I'm a novice 🙂 I need to count instruments within a set of specific types and for a specific financial year IF they have also have a specific set of offences listed. ...
  • krishnakanth240's avatar
    1 month ago

    Hi Peterdown 

    Double counting is because you are calculating A, B, and C separately then adding. Instrument matching both 5D(1)(c) and 5D(5A) gets counted once in A and once in B. You can combine with OR in a CALCULATE where each instrument is only counted once

     

    MEASUREA1 =

    CALCULATE(

    DISTINCTCOUNT('prod extract'[instrument_number]),

    LEFT('prod extract'[instrument_type],3) IN {"s46","s48"},

    'prod extract'[issued_date_financial_year] IN VALUES(refdata[current_year]),

    FILTER(

    'prod extract',

     CONTAINSSTRINGEXACT('prod extract'[offence_list],"5D(1)(c)")

            || CONTAINSSTRINGEXACT('prod extract'[offence_list],"5D(5A)")

            || CONTAINSSTRINGEXACT('prod extract'[offence_list],"5D(2)(a)(b)(iv)")

        )

    )

     

    For your other measures with up to 7 references, add more || conditions inside FILTER