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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
ryan_b_fiting
Post Patron
Post Patron

DAX to calculate future booked appointments

Hello Community - 

I am trying to figure out how to write a measure to calculate the Total Future Appointments Booked for my providers.  I am displaying in a table view by patient, so when a provider looks at the report, they see their schedule for the next N days (7 days, 1 month etc) based on the relative date slice they select by patient.

 

What I need to include in that table is a measure that will show them how many FUTURE appointments that patient has booked beyond the max date of that relative slicer.

 

Here is a sample of data and an expected output:

AppointmentIDAppointment DatePatient IDAppt Type
110/1/202211Acu
211/1/202211Acu Wellness
312/1/202211Acu
410/21/202222Acu 30
510/31/202233Acu 30
611/15/202222Acu 30
712/1/202222Wellness
812/22/202233Wellness
91/3/202322Acu 60
101/9/202333Wellness
    

 

Expected Output:  Future Booked Appointments and Next Appt Type are what I am trying to calculate.

 

Date Slicer 10/1/22 - 10/31/22 
   
Patient IDFuture Booked AppointmentsNext Appt Type
112Acu Wellness
223Acu 30
332Wellness

 

Then if they switch the relative date slicer, the future bookings and Next Appt Type will adjust accordingly.

 

Any help on this would be greatly appreciated, I have been wrapped up in this for the last few days with no luck and I have a call with my providers later today where I am hoping to show the new report!

 

Thanks for all the help!

Ryan F

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @ryan_b_fiting 

 

Please try the following:

 

Starting Table in POwer Query:

Mikelytics_2-1668532905780.png

 

 

Following data model. I assume that you have a separate date table with a link to the appointment date

Mikelytics_1-1668532820927.png

 

as a starting point I create a table visual with patient ID as well as slicers for my time selection. As an example I chose Oct 2022, so max date is 31.10.2022. Please be aware that the IDs have to be Text type or they can be number type but then you need to turn off autom summarization

 

Mikelytics_5-1668533424628.png

 

 

Now I create my first measure for future appointments and put it intpo the table

 

 

 

NumberOfFutureAppointments = 

var var_LastDateSelected = LASTDATE(DimDate[Date])

RETURN

CALCULATE(
    COUNTROWS(Fact_Appointments),
    ALL(DimDate),
    Fact_Appointments[Appointment Date] > var_LastDateSelected
)

 

 

 

Mikelytics_4-1668533388228.png

 

Now I create the emasure for the next appointment Type and add it to the table

 

 

 

NextAppointment = 

var var_LastDateSelected = LASTDATE(DimDate[Date])

var var_NextDateAfterMaxDate =
    CALCULATE(
            FIRSTDATE(Fact_Appointments[Appointment Date]),
            ALL(DimDate),
            Fact_Appointments[Appointment Date] > var_LastDateSelected
        )

RETURN
CALCULATE(
    CONCATENATEX(
        VALUES(Fact_Appointments[Appt Type]),
        [Appt Type],","
    )
    ,
    ALL(DimDate),
    Fact_Appointments[Appointment Date] = var_NextDateAfterMaxDate
)

 

 

 

Mikelytics_6-1668534045888.png

 

Mikelytics_9-1668534251405.png

 

when I put the slicer on November:

Mikelytics_10-1668534274632.png

 

 

 

It should also work with daily dates and so on.

 

The total shows the next appointment over all patients but you can also turn it off if you do not need it.

 

@ryan_b_fiting  I use CONCATENATEX to cover the situation when on the next available dates there are different appointment types. Look for example on the total for November. on 01.12.22 one of the pateience has Acu and one has wellenes. And because for both patients the next treatment is on the same day the total shows both them.

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

 

 

 

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

2 REPLIES 2
sevenhills
Super User
Super User

If you dont have date table and only one table, you can try this

Next Appointment Type = 
VAR _d = LASTDATE(Table1[Appointment Date]) 
VAR _P = SELECTEDVALUE(Table1[Patient ID])
VAR _FirstApptID = CALCULATE(
	Min(Table1[AppointmentID]),
    FILTER( all(Table1), Table1[Appointment Date] > _d && Table1[Patient ID] = _P ) 
    )
RETURN CALCULATE( CONCATENATEX(
                VALUES(Table1[Appt Type]), [Appt Type],","), 
                Filter(all(Table1), Table1[AppointmentID] = _FirstApptID)) 
Future Booked Appointments = 
VAR _d = LASTDATE(Table1[Appointment Date]) 
VAR _P = SELECTEDVALUE(Table1[Patient ID])

RETURN CALCULATE(
	COUNTROWS('Table1'),
    FILTER( all(Table1), Table1[Appointment Date] > _d && Table1[Patient ID] = _P ) 
    )

 

Output

sevenhills_0-1668552429329.png

 

Note: Recommended to have date table. 

 

Mikelytics
Resident Rockstar
Resident Rockstar

Hi @ryan_b_fiting 

 

Please try the following:

 

Starting Table in POwer Query:

Mikelytics_2-1668532905780.png

 

 

Following data model. I assume that you have a separate date table with a link to the appointment date

Mikelytics_1-1668532820927.png

 

as a starting point I create a table visual with patient ID as well as slicers for my time selection. As an example I chose Oct 2022, so max date is 31.10.2022. Please be aware that the IDs have to be Text type or they can be number type but then you need to turn off autom summarization

 

Mikelytics_5-1668533424628.png

 

 

Now I create my first measure for future appointments and put it intpo the table

 

 

 

NumberOfFutureAppointments = 

var var_LastDateSelected = LASTDATE(DimDate[Date])

RETURN

CALCULATE(
    COUNTROWS(Fact_Appointments),
    ALL(DimDate),
    Fact_Appointments[Appointment Date] > var_LastDateSelected
)

 

 

 

Mikelytics_4-1668533388228.png

 

Now I create the emasure for the next appointment Type and add it to the table

 

 

 

NextAppointment = 

var var_LastDateSelected = LASTDATE(DimDate[Date])

var var_NextDateAfterMaxDate =
    CALCULATE(
            FIRSTDATE(Fact_Appointments[Appointment Date]),
            ALL(DimDate),
            Fact_Appointments[Appointment Date] > var_LastDateSelected
        )

RETURN
CALCULATE(
    CONCATENATEX(
        VALUES(Fact_Appointments[Appt Type]),
        [Appt Type],","
    )
    ,
    ALL(DimDate),
    Fact_Appointments[Appointment Date] = var_NextDateAfterMaxDate
)

 

 

 

Mikelytics_6-1668534045888.png

 

Mikelytics_9-1668534251405.png

 

when I put the slicer on November:

Mikelytics_10-1668534274632.png

 

 

 

It should also work with daily dates and so on.

 

The total shows the next appointment over all patients but you can also turn it off if you do not need it.

 

@ryan_b_fiting  I use CONCATENATEX to cover the situation when on the next available dates there are different appointment types. Look for example on the total for November. on 01.12.22 one of the pateience has Acu and one has wellenes. And because for both patients the next treatment is on the same day the total shows both them.

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

 

 

 

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.