Forum Discussion
Counting distinct list against multiple contain strings
- 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
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
- Peterdown1 month agoFrequent Visitor
Thanks for the assistance. I can now understand where to place the FILTER function within an existing set of conditions. 🙂