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
shug
New Member

Help with DAX

DAX measure to show which patient has completed a 'cosmetic' treatment within 4 weeks of completing an 'examination' treatment.

E.g. an examination on the 01/02/2023 and cosmetic on the 10/02/2023 would be marked as 1 whereas if the examination happened on 01/02/2023 and 'cosmetic' on the 20/03/2023, it would be marked as 0. A patient may also have a future examination and future cosmetic so it should pick up those as well.


Patientkey is in 'treatments' table but 'patient name'  is from the 'patients' table. Rest of the columns are in 'Treatments'

 

PatientKeyCompleted DatePatient NameTreatment CategoryNo. of Items 
111/01/2023 12:20AExaminations1 
114/02/2023 13:18ACosmetic1 
107/03/2023 15:59AExaminations1 
129/03/2023 15:50ATreatment Stages1 
129/03/2023 15:50ARestorative1 
117/04/2023 15:54AProsthodontics1 
117/04/2023 15:54AProsthodontics1 
212/01/2023 15:42BOrthodontics1 
212/01/2023 15:44BOrthodontics1 
201/03/2023 16:34BExaminations1 
201/03/2023 16:39BMiscellaneous1 
201/03/2023 16:39BOrthodontics1 
201/03/2023 16:39BOrthodontics1 
202/03/2023 15:16BMiscellaneous1 
202/03/2023 17:03BMiscellaneous1 
209/03/2023 14:37BExaminations1 
203/04/2023 16:58BMiscellaneous1 
225/04/2023 09:47BExaminations1 
228/06/2023 13:00BExaminations1 
228/06/2023 13:00BNon-Clinical Services1 
230/06/2023 13:09BExaminations1 
230/06/2023 13:09BTreatment Stages1 
214/07/2023 12:51BCosmetic1 
1 REPLY 1
rajendraongole1
Super User
Super User

Hi @shug - Try the below calculated columns and measure with flag as patient has completed a 'cosmetic' treatment within 4 weeks of completing an 'examination' treatment., if still issue not resolved.

 

rajendraongole1_0-1719132802729.png

IsCosmeticWithin4Weeks =
VAR CurrentTreatmentDate = 'Cosmetic'[Completed Date]
VAR CurrentPatientKey = 'Cosmetic'[PatientKey]
VAR ExaminationDates =
    FILTER(
        'Cosmetic',
        'Cosmetic'[PatientKey] = CurrentPatientKey &&
        'Cosmetic'[Treatment Category] = "Examinations" &&
        'Cosmetic'[Completed Date] <= CurrentTreatmentDate &&
        'Cosmetic'[Completed Date] > CurrentTreatmentDate - 28
    )
VAR HasRecentExamination = COUNTROWS(ExaminationDates) > 0
RETURN
IF(
    'Cosmetic'[Treatment Category] = "Cosmetic" && HasRecentExamination,
    1,
    0
)
 
create a aggregated results for each patient use measure:
 
CompletedCosmeticWithin4Weeks =
CALCULATE(
SUM('Treatments'[IsCosmeticWithin4Weeks]),
ALLEXCEPT('Treatments', 'Treatments'[PatientKey])
)
 
last apply the flag 0 or 1 condition on table. as below one more measure create it.
PatientCompletedCosmeticWithin4Weeks =
IF(
[CompletedCosmeticWithin4Weeks] > 0,
1,
0
)
 
rajendraongole1_1-1719132878706.png

 

 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.