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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ranis1227
Helper I
Helper I

Dax for grouping by compliance?

Hello,

 

I am trying to get compliance whether the patient took a drug screen or not.  Here are some example data:

ranis1227_0-1656506309572.png

 

For clinic A the compliance is 87.5%, 7 (number of distinct patients who took a drug screen)/8 total number of  distinct patients in clinic A.  For clinic B the compliance is 50% (1/2).  

 

Is there a way to do this with dax?  Please reach out if you need additional information.  

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ranis1227 , try measure

 

Divide(calculate(sum(Table[patients]), filter(Table, Table[drugscreen] = "Y")),sum(Table[patients]))

View solution in original post

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi @ranis1227 ,

 

You may try this Measure.

compliance =
VAR PatientsWithGrugScreen =
    CALCULATE (
        [Distinct Count Patients],
        FILTER ( DrugScreen, DrugScreen[GrugScreen] = "Y" )
    )
VAR ClinicPatients =
    CALCULATE ( [Distinct Count Patients], VALUES ( DrugScreen[Department] ) )
RETURN
    DIVIDE ( PatientsWithGrugScreen, ClinicPatients )

 

The result looks like this.

vcazhengmsft_0-1656915679829.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

Thank you very much. This works perfectly. 

amitchandak
Super User
Super User

@ranis1227 , try measure

 

Divide(calculate(sum(Table[patients]), filter(Table, Table[drugscreen] = "Y")),sum(Table[patients]))

Amit, 

 

I tried it and it worked for the sum of total patients. 

 

However, I need it for the distinct number of patients.  I used 

Distinct Count Patients = DISTINCTCOUNT(DrugScreen[PTNAME]).  There are duplicate patient visits for each clinic.  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors