Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
TSK
Frequent Visitor

DAX for Measure

I need help in creating measure, I have 3 tables 1) Patient Name 2) Patient Diagnosis 3) Medicene Consumed. I have linked diagnosis and medicene table with Patient Name table via ID. Now I want a measure which can calculate that how many patients are diagnosed as "Fever" and consumed "Panadol" and "Arinac". Below are the tables for reference in this case answer is 2, Patient with ID 1 and 5 are Diagnosed as Fever and Consumed "Panadol" and "Arinac". How can I achieve this via measure.

Patient Name:

IDName
1Ahmed
2Rafiq
3Saleem
4Jospeh
5David

 

Patient Diagnosis:

IDDiagnosis
1Fever
2Flu
3Flu
4Flu
5Fever

 

Medicene Consumed:

IDMedicine Name
1Panadol
1Brufen
1Arinac
2Panadol
2Arinac
3Panadol
4Panadol
5Panadol
5Arinac
1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

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:

image.png

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

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

1 REPLY 1
TomMartens
Super User
Super User

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:

image.png

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

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.