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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Syndicate_Admin
Administrator
Administrator

How to avoid Book slots double bookings same time and date?

Filter(Sort(col_Desks,Title),Active=1&& Not(// Not reserved for the selected date and time span
Title in Filter(col_Reservations,(DateTimeValue(Text('Check Out From Text',DateTimeFormat.ShortDate)) >=DateTimeValue(Text(startTime,DateTimeFormat.ShortDate))||
DateTimeValue(Text('Check Out To Text',
DateTimeFormat.ShortDate))>DateTimeValue(Text(endTime,DateTimeFormat.ShortDate)))
//&&// Same dateMeeting Rooms/ Desks Selections Screen)
.Title),MaxCapacity>=CountRows(NameOfPeopleComboBoxNewBooking.SelectedItems)&&MinCapacity<=CountRows(NameOfPeopleComboBoxNewBooking.SelectedItems))

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Not working, same error showing both meeting room same time and date.

 

I have attached the image also please check. 

View solution in original post

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Not working, same error showing both meeting room same time and date.

 

I have attached the image also please check. 

amustafa
Super User
Super User

To avoid double bookings for the same time and date in a PowerApp, especially when dealing with resources like meeting rooms or desks, you need to create a logical filter that checks for existing reservations before allowing a new booking. The approach you're taking is generally correct, but let's refine it to ensure it effectively prevents double bookings.

Your current formula is a good start, but it seems a bit complex and might be missing some elements for clarity. The key is to ensure that for any given slot you want to book, there are no existing reservations that overlap with it. Here’s a more streamlined approach:

1. Define the Time Range for the New Booking: You need to have a clear definition of the start and end time for the new booking. Let’s assume `startTime` and `endTime` are your variables holding these values.

2. Filter the Available Slots: You need to filter your `col_Desks` (or any other resource collection) to find those that are not reserved during the specified time range.

3. Check for Overlapping Bookings: The main part of the filter will check for overlapping bookings. A booking overlaps if either:
- It starts before the new booking ends and ends after the new booking starts.
- It starts and ends within the new booking time frame.

Here is a simplified version of the formula that you might use:


Filter(
col_Desks,
Active = 1,
Not(
Title in Filter(
col_Reservations,
(DateTimeValue(Text(CheckOutFrom, DateTimeFormat.ShortDate)) < DateTimeValue(Text(endTime, DateTimeFormat.ShortDate))
&&
DateTimeValue(Text(CheckOutTo, DateTimeFormat.ShortDate)) > DateTimeValue(Text(startTime, DateTimeFormat.ShortDate)))
).Title
),
MaxCapacity >= CountRows(NameOfPeopleComboBoxNewBooking.SelectedItems),
MinCapacity <= CountRows(NameOfPeopleComboBoxNewBooking.SelectedItems)
)


In this formula:
- `CheckOutFrom` and `CheckOutTo` should be fields in your `col_Reservations` collection that indicate the start and end times of existing bookings.
- `DateTimeValue(Text(..., DateTimeFormat.ShortDate))` is used to ensure that the times are correctly formatted and comparable.

This formula assumes:
- `col_Desks` is your collection of bookable resources.
- `col_Reservations` is your collection of existing bookings.
- `MaxCapacity` and `MinCapacity` are fields in `col_Desks` that define the capacity limits for the resource.

Remember, PowerApps formulas can be quite sensitive to syntax and context, so you might need to adjust this based on your specific app's design and data structure. Always test thoroughly to ensure it handles all booking scenarios correctly.





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

Proud to be a Super User!




Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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