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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Add Duration to the last appointment of the day

Hello,

 

I'm trying to calculate the number of hours worked on a date from a Doctors template.  For example, on 4/3 Doctor A had scheduled appointments from 8-3:30.  The measure I'm using now calculates this to 7 hours 30 minutes however, the last appointment was at 3:30 and was 15 minutes in duration.  In h:mm the duration of the worked day should be 7:45.  

 

The table is structured as following:

appt schdlng prvdr apptdate apptstarttime apptslotduration

Doctor A4/3/20238:00 AM15
Doctor A4/3/20238:15 AM15
Doctor A4/3/20238:30 AM30
Doctor A4/3/20239:15 AM15
Doctor A4/3/20239:30 AM30
Doctor A4/3/20239:30 AM15
Doctor A4/3/202310:00 AM15
Doctor A4/3/202310:15 AM15
Doctor A4/3/202310:30 AM30
Doctor A4/3/202311:00 AM15
Doctor A4/3/202311:15 AM15
Doctor A4/3/20231:00 PM30
Doctor A4/3/20232:00 PM15
Doctor A4/3/20232:00 PM15
Doctor A4/3/20232:15 PM15
Doctor A4/3/20232:30 PM30
Doctor A4/3/20232:45 PM15
Doctor A4/3/20233:00 PM15
Doctor A4/3/20233:15 PM15
Doctor A4/3/20233:30 PM15

 

the measures I've tried:

  • First Appt = min(Sheet1[apptstarttime])
  • last appt time = max(Sheet1[apptstarttime])
  • Scheduled Day = [First Appt]-[last appt time]

 

The report resembles:

ChaseG_0-1684200270192.png

 

In summary, on 4/3 the Doctor's first appointment was at 8am and the last at 3:30 however the duration of the 3:30 appoinment was 15 minutes.  I need the last appt time measure to include the duration so it says 3:45 and then the Scheduled day to be 7:45.  A better name for this measure might be "End Time - Last Appointment".

 

Any help is appreciated.

 

Thank you!

 
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Anonymous 

not sure if i fully get you, try like:

Scheduled Day = 
VAR _lastappttime = [last appt time]
VAR _lastduration =
MAXX(
    FILTER(
        ALL(Sheet1),
       Sheet1[apptstarttime]=_lastappttime
    ),
    Sheet1[apptslotduration]
)
RETURN
[last appt time] -[First Appt] + _lastduration/24/60

it worked like:

FreemanZ_0-1684201500683.png

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@FreemanZ 

 

This worked perfectly for the sample I prepared for the community but for my business case, it seems to be adding 60 minutes to every last appointment for each Doctor.  Is is possilbe it's returning the MAX appt duration across all Doctors for each appointment date?  I think I may have solved the issue, see below.

 

This is the result I get from my real case:

appt schdlng prvdrapptdateFirst ApptLast ApptScheduled Day
Doctor A4/3/2023 0:008:00:003:30:008:30:00

 

I tried removing the ALL in the line above and I think that gives me what I want since I believe the ALL ingores the context imparted by the provider attribute (is that the correct theory?  I'm still learning DAX).

 

Thanks @FreemanZ , I'll mark this as solved.

FreemanZ
Super User
Super User

hi @Anonymous 

not sure if i fully get you, try like:

Scheduled Day = 
VAR _lastappttime = [last appt time]
VAR _lastduration =
MAXX(
    FILTER(
        ALL(Sheet1),
       Sheet1[apptstarttime]=_lastappttime
    ),
    Sheet1[apptslotduration]
)
RETURN
[last appt time] -[First Appt] + _lastduration/24/60

it worked like:

FreemanZ_0-1684201500683.png

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.