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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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