web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Double booking of room...
Power Apps
Answered

Double booking of room between two dates (simple fix)!

(0) ShareShare
ReportReport
Posted on by

Hi all,

 

Im sure this is a simple fix for you clever people, but Im just learning the ropes.

 

I have a auto generated power app connected to a simple sharepoint list.

 

The SharePoint list name is Wallan. 

columns in the list are; Unit number, Entry date, Exit date.

Unit number has three options: Unit 1, Unit 2, unit 3.
Entry date, and exit date are both date fields

 

Within the powerapp, I want the user to be alerted and prevented from booking if the selected unit is already booked within the requested date range.

 

If the notification/pop up also included information in the text about when the unit is booked until, that would be fantastic.

 

Thank you

 

 

Categories:
  • Waegemma Profile Picture
    583 Super User 2024 Season 1 on at

    Hi @Matt-BH ,

     

    I took the liberty of changing the column names to versions without spaces: Unit, Entry_Date, Exit_Date.

     

     

    Waegemma_0-1667526599884.png

    Put this code in the OnSelect of the "Book" Button:

     

     

    ClearCollect(
     colBookedDates,
     Filter(
     Wallan,
     Or(
     Unit = dropUnit.Selected.Value && Entry_Date <= dpEntry_Date.SelectedDate && Exit_Date >= dpEntry_Date.SelectedDate,
     Unit = dropUnit.Selected.Value && Entry_Date <= dpExit_Date.SelectedDate && Exit_Date >= dpExit_Date.SelectedDate
     )
     )
    );
    If(
     Not(IsEmpty(colBookedDates)),
     Notify(
     Concatenate(
     dropUnit.Selected.Value,
     " is booked:",
     Concat(
     colBookedDates,
     " from " & Entry_Date & " to " & Exit_Date & ", "
     )
     )
     ),
     Patch(
     Wallan,
     Defaults(UnitBooking),
     {
     Entry_Date: dpEntry_Date.SelectedDate,
     Exit_Date: dpExit_Date.SelectedDate,
     Unit: dropUnit.Selected.Value
     }
     )
    )

     

     

    Greetings,

     

    Marc

  • Matt-BH Profile Picture
    on at

    Hi Marc, I copied your example, created a new list that reflected the naming, but am getting errors

    What I did;

    Created a new SharePoint list called wallan_test 

    Went to intergrate -> Powerapps -> create new app (the app was auto created)

    Added your code to the submit button.

     

    Got the following errrors..

     

    MattBH_0-1667534382146.png

     

  • Matt-BH Profile Picture
    on at

    ClearCollect(
    colBookedDates,
    Filter(
    Wallan_test,
    Or(
    Unit = dropUnit.Selected.Value && Entry_Date <= dpEntry_Date.SelectedDate && Exit_Date >= dpEntry_Date.SelectedDate,
    Unit = dropUnit.Selected.Value && Entry_Date <= dpExit_Date.SelectedDate && Exit_Date >= dpExit_Date.SelectedDate
    )
    )
    );
    If(
    Not(IsEmpty(colBookedDates)),
    Notify(
    Concatenate(
    dropUnit.Selected.Value,
    " is booked:",
    Concat(
    colBookedDates,
    " from " & Entry_Date & " to " & Exit_Date & ", "
    )
    )
    ),
    Patch(
    wallan_test,
    Defaults(UnitBooking),
    {
    Entry_Date: dpEntry_Date.SelectedDate,
    Exit_Date: dpExit_Date.SelectedDate,
    Unit: dropUnit.Selected.Value
    }
    )
    )

  • Matt-BH Profile Picture
    on at

    MattBH_1-1667534907018.png

     

  • Matt-BH Profile Picture
    on at

    Im not understanding how this fits in;

    MattBH_0-1667536272590.png

    Do I need to create separate fields? If so where?

     

    My screen looks like this;

    MattBH_2-1667536399211.png

     

     

    MattBH_1-1667536332416.png

     

    Thank you, look forward to your reply

  • Matt-BH Profile Picture
    on at

    @Waegemma 

     

  • Waegemma Profile Picture
    583 Super User 2024 Season 1 on at

    Hi @Matt-BH ,

     

    Ok, if you work with a form, we have to adapt some things:

    Forget about the controls I used.

     

    In the code:

    Replace 'dropUnit' with the dropdown on the form: 'DatacardValueX' of the Unit Field.

    Replace 'dpEntry_Date' with the dropdown on the form: 'DatacardValueX' of the Entry_Date Field.

    Replace 'dpExit_Date' with the dropdown on the form: 'DatacardValueX' of the Exit_Date Field.

     

    In the Submit button:

     

    ClearCollect(
     colBookedDates,
     Filter(
     Wallan,
     Or(
     Unit = dropUnit.Selected.Value && Entry_Date <= dpEntry_Date.SelectedDate && Exit_Date >= dpEntry_Date.SelectedDate,
     Unit = dropUnit.Selected.Value && Entry_Date <= dpExit_Date.SelectedDate && Exit_Date >= dpExit_Date.SelectedDate
     )
     )
    );
    If(
     Not(IsEmpty(colBookedDates)),
     Notify(
     Concatenate(
     dropUnit.Selected.Value,
     " is booked:",
     Concat(
     colBookedDates,
     " from " & Entry_Date & " to " & Exit_Date & ", "
     )
     )
     ),
     SubmitForm(Form1)
     )
    )

     

    Greetings,

    Marc

     

  • Matt-BH Profile Picture
    on at

    I think we are close, please see below;

     

    The = sign is erroring with: 

    MattBH_1-1667558913511.png

     

    Then further;

    MattBH_2-1667558973511.png

     

     

    Thank you

     

    MattBH_0-1667558855917.png

     

  • Matt-BH Profile Picture
    on at
  • Waegemma Profile Picture
    583 Super User 2024 Season 1 on at

    Hi @Matt-BH ,

     

    You used the property 'SelectedItems' instead of  the 'Selected.Value' I use in my code.

     

    See it? Don't worry, it's a common mistake!

     

    Marc

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 258

#3
Mohsin Ali Profile Picture

Mohsin Ali 231

Last 30 days Overall leaderboard