Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi Experts,
Attached is my PBIX with Datamodel.
Hospital_Outpatients_Waittime.pbix
I am finding it challenging to achieve the correct results for wait time based on the following logic:
Wait Time Calculation Logic:
Wait Time =
IF (
'Invoice_statushis'[Created_on_Time] (Status = 'Checked In') < 'Appointment'[Start_time],
'Invoice_statushis'[Created_on_Time](Status = 'Consult Start') - Appointment.AppointmentTime,
'Invoice_statushis'[Created_on_Time](Status = 'Consult Start') - Invoice_statushis'[Created_on_Time](Status = 'Checked In')
)
Anyone, Please Help!!
Solved! Go to Solution.
Try this and see
Add this column to your appointment table!
Column Wait Times =
-- Get the invoice id of the same patient id and same date
var _inv_pid_appt2 = CALCULATE( MAX(Invoice[_id]), FILTER( ALLSELECTED(Invoice), Invoice[patient_id] = appointment[patient_id] && Invoice[date].[Date] = appointment[Start_time].[Date]) )
-- Get the checked in record time of the same invoice id
var _inv_statushis_pid_appt2_checkedIn = CALCULATE( MAX(Invoice_statushis[Created_on_Time]), FILTER( ALL(Invoice_statushis), Invoice_statushis[invoice_id] = _inv_pid_appt2 && Invoice_statushis[Status] = "Checked In") )
-- Get the consult start record time of the same invoice id
var _inv_statushis_pid_appt2_consultin = CALCULATE( MAX(Invoice_statushis[Created_on_Time]), FILTER( ALL(Invoice_statushis), Invoice_statushis[invoice_id] = _inv_pid_appt2 && Invoice_statushis[Status] = "Consult Start") )
RETURN
IF (
_inv_statushis_pid_appt2_checkedIn < appointment[Start_time],
DATEDIFF(_inv_statushis_pid_appt2_consultin, appointment[Start_time], MINUTE),
DATEDIFF( _inv_statushis_pid_appt2_consultin, _inv_statushis_pid_appt2_checkedIn, MINUTE)
)
First, I tried getting the invoice id for the same patient id and patient appointment date.
Second, I used the invoice id and then filter the checked in and consult start events and get the max time
Third and last step, tried to do your logic calculation. You may have to tune further this step as it does not make sense purely if statement vs true condition calc. My thinking says as
Glad to hear it helped!
Try this and see
Add this column to your appointment table!
Column Wait Times =
-- Get the invoice id of the same patient id and same date
var _inv_pid_appt2 = CALCULATE( MAX(Invoice[_id]), FILTER( ALLSELECTED(Invoice), Invoice[patient_id] = appointment[patient_id] && Invoice[date].[Date] = appointment[Start_time].[Date]) )
-- Get the checked in record time of the same invoice id
var _inv_statushis_pid_appt2_checkedIn = CALCULATE( MAX(Invoice_statushis[Created_on_Time]), FILTER( ALL(Invoice_statushis), Invoice_statushis[invoice_id] = _inv_pid_appt2 && Invoice_statushis[Status] = "Checked In") )
-- Get the consult start record time of the same invoice id
var _inv_statushis_pid_appt2_consultin = CALCULATE( MAX(Invoice_statushis[Created_on_Time]), FILTER( ALL(Invoice_statushis), Invoice_statushis[invoice_id] = _inv_pid_appt2 && Invoice_statushis[Status] = "Consult Start") )
RETURN
IF (
_inv_statushis_pid_appt2_checkedIn < appointment[Start_time],
DATEDIFF(_inv_statushis_pid_appt2_consultin, appointment[Start_time], MINUTE),
DATEDIFF( _inv_statushis_pid_appt2_consultin, _inv_statushis_pid_appt2_checkedIn, MINUTE)
)
First, I tried getting the invoice id for the same patient id and patient appointment date.
Second, I used the invoice id and then filter the checked in and consult start events and get the max time
Third and last step, tried to do your logic calculation. You may have to tune further this step as it does not make sense purely if statement vs true condition calc. My thinking says as
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 5 |
| User | Count |
|---|---|
| 24 | |
| 11 | |
| 11 | |
| 9 | |
| 8 |