Forum Discussion
DAX for Measure
- 6 years ago
Hey TSK ,
this DAX measure allows counting the patients, who are consuming the selected medicine:
complex count = var patients = CALCULATETABLE( VALUES('Patient Name'[ID]) , 'Patient Diagnosis' , 'Medicine Consumed' ) var medicineconsumed = VALUES('Medicine Consumed'[Medicine Name]) return COUNTROWS( FILTER( patients , countrows( INTERSECT( CALCULATETABLE( VALUES('Medicine Consumed'[Medicine Name]) ) , medicineconsumed )) = COUNTROWS(medicineconsumed) ) )This allows to count the patients who are consuming at least both of selected medicines, please be aware that the screenshot show the number of patients diagnosed with the flu:
If you are looking for a measure that counts the patients who are consuming exactly the selected medicines, things become a little more complex. In your example, patient 1 also consumes the medicament Brufen, but is counted as this patient also takes both of the selected medicines.
Hopefully, this helps to tackle your challenge.
Regards,
Tom
Hey TSK ,
this DAX measure allows counting the patients, who are consuming the selected medicine:
complex count =
var patients =
CALCULATETABLE(
VALUES('Patient Name'[ID])
, 'Patient Diagnosis'
, 'Medicine Consumed'
)
var medicineconsumed = VALUES('Medicine Consumed'[Medicine Name])
return
COUNTROWS(
FILTER(
patients
, countrows(
INTERSECT(
CALCULATETABLE(
VALUES('Medicine Consumed'[Medicine Name])
)
, medicineconsumed
))
= COUNTROWS(medicineconsumed)
)
)
This allows to count the patients who are consuming at least both of selected medicines, please be aware that the screenshot show the number of patients diagnosed with the flu:
If you are looking for a measure that counts the patients who are consuming exactly the selected medicines, things become a little more complex. In your example, patient 1 also consumes the medicament Brufen, but is counted as this patient also takes both of the selected medicines.
Hopefully, this helps to tackle your challenge.
Regards,
Tom