Forum Discussion
Calculating Counts within a date range PLUS future dates based on Criteria
- Anonymous3 years ago
Hi ryan_b_fiting ,
You could try these measures.
NPE Date = CALCULATE ( MAX ( 'ENCOUNTERS TABLE'[EncounterDate] ), FILTER ( 'ENCOUNTERS TABLE', [EncounterType] = "Acu NPE" ) )NPE Date in Appointments = CALCULATE ( MAX ( 'ENCOUNTERS TABLE'[EncounterDate] ), FILTER ( 'ENCOUNTERS TABLE', [ProviderID] = MAX ( 'APPOINTMENTS TABLE'[ProviderID] ) && [EncounterType] = "Acu NPE" ) )Booked/Completed Post NPE = IF ( [NPEs] <> 0, CALCULATE ( COUNT ( 'ENCOUNTERS TABLE'[ProviderID] ), FILTER ( 'ENCOUNTERS TABLE', [EncounterDate] > [NPE Date] ) ) + CALCULATE ( COUNT ( 'APPOINTMENTS TABLE'[ProviderID] ), FILTER ( 'APPOINTMENTS TABLE', [AppointmentDate] > [NPE Date in Appointments] && [ProviderID] = MAX ( 'ENCOUNTERS TABLE'[ProviderID] ) ) ), 0 )The two dates are measured by comparing dates with the APPOINTMENTS table and the ENCOUNTERS table, respectively.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ryan_b_fiting , Assuming ProviderID is coming from common dim
Try measures like
M1= calculate(Count(Table1[AppointmentType]) , filter(allselected(Provider), provide[ProviderID] = max( provide[ProviderID] ) )
M2= countx(filter(Table2, Containsstrings(Table2[EncounterType],"NPE")), Table2[ProviderID])
m3= if([M2] <> blank() && [M2]<> 0, [M1],0)
- ryan_b_fiting3 years agoPost Patron
Thanks for the reply amitchandak but I do not think these measures are what I am looking for. M1 would only count data from the appointments table which is only future bookings, and those appointments do not fall within the sliced date range.
I would need the future bookings+visits that happened within the sliced date range.
Also, I think I may need to add a few more lines of data to my sample data.
APPOINTMENTS
ProviderID PatientID AppointmentID AppointmentDate AppointmentType 11 1 12 1/2/2023 Acu-Normal 11 1 13 1/9/2023 Acu-Normal 11 1 14 1/16/2023 Acu-Normal 11 1 15 1/23/2023 Acu-Normal 15 2 16 1/8/2023 Acu-Specialty 18 7 21 1/22/2023 Acu-Specialty 15 12 22 1/23/2023 Acu-Specialty ENCOUNTERS:
ProviderID PatientID EncounterID EncounterDate EncounterType 11 1 7 12/21/2022 Acu NPE 15 2 8 12/23/2022 Acu NPE 11 1 9 12/23/2022 Acu-Specialty 18 7 10 12/23/2022 Acu-Normal 11 3 11 12/24/2022 Acu-Normal 11 4 12 12/24/2022 Acu-Specialty EXPECTED OUTPUT:
ProviderID Encounters NPEs Booked/Completed Post NPE 11 4 1 5 15 1 1 1 18 1 0 0 Booked or completed Post NPE are ONLY for the patients who had an NPE visit during the selected period