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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Limit number of bookings
Power Apps
Unanswered

Limit number of bookings

(0) ShareShare
ReportReport
Posted on by

Hi all,

 

I have a Book button to book a desk.

How to limit number of bookings (total 1 or total 2) during the day?

kinghnvn_0-1640055560172.png

@StalinPonnusamy 

 

Categories:
I have the same question (0)
  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    I would do this utilising DisplayMode for the button, a Label for user journey and a countrows with a filter.
    Step One: change the button's DisplayMode to If(CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate = Today()))>=2, DisplayMode.Disabled,DisplayMode.Edit)

    Step Two: change the label's Visible property to: CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate = Today()))>=2

    Step Three: change the label's text to something like. "You cannot Book more than Two Desks in one Day"

    Ensure you tweak my formula to matchup with your datasource  an situation. everything in red probably needs to be changed the blue part for Today() may need to change if they are using a dataselector to book for the future.


    If you need more help on how to apply this to your circumstance please provide the name of the Datasource and the column name / column type referencing who booked it. Then also let me know how they are picking the day is it a DataSelector or always Today()

  • kinghnvn Profile Picture
    on at

    I'm using DisplayMode for the Button as below.

    How to combine your code?

     

    If(
    !IsBlank(
    LookUp(
    DeskBooking,
    Employee.Email = UserInfo.Email && MySlotTime
    )
    ),
    DisplayMode.Disabled,
    !IsBlank(
    LookUp(
    DeskBooking,
    MySlotTime && Title = MainGallery.Selected.Title
    )
    ),
    DisplayMode.Disabled
    )

  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @kinghnvn 

     

    First, you can combine your current code like

    If(
    !IsBlank(LookUp(DeskBooking,Employee.Email = UserInfo.Email && MySlotTime)) ||
    !IsBlank(LookUp(DeskBooking,MySlotTime && Title = MainGallery.Selected.Title)),
    DisplayMode.Disabled,DisplayMode.Edit
    )

     

    Second, You are using Calander control which has a Date Range so Changing your current display mode may be challenging since we need to loop through the selected dates to check each date.

     

    So, We need to validate this logic on the "OnSelect" of the Book button.

     

    Logic concept

    • Declare a local variable to false
    • Loop through the Calander Dates
    • Get each single date
    • Get the Booking count for each day
    • If any one of the days is more than 2 then set the variable to true
    • Finally, verify No days has more than 2
      • If Yes through the message or display Label
      • If No then Patch or Save
    UpdateContext({IsMorethan2Bookings : false});
    
    ForAll(DateDiff(Calander1.StartDate, Calander1.EndDate),
    If(CountRows(
    Filter(OfficeBooking, 
    EmployeePerson.Email = UserInfo.Email && BookingDate = DateAdd(Calander1.StartDate, ThisRecord.Value,Days)
    )) >= 2,UpdateContext({IsMorethan2Bookings : true});
    ) //If
    ); //ForAll
    
    If(IsMorethan2Bookings, Notify("You can't book more than two desks in single day"),
    Patch(.....)
    )


    Thanks,
    Stalin - Learn To Illuminate

      

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    Is this a displaymode if statement for a different reason or for the same issue. if it is for a different thing i know just where to insert our bit but if you are attempting to resolve the same thing we will likely just need to replace it 🙂 . Also is MySlotTime a column in the datasource and is it date only or date and time if so or is it some other data type. This will help me understand the situation so we can adapt my suggestion 🙂

     

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    I just noticed that @StalinPonnusamy has popped in to offer assistance reply @AJ_Z  to me if you still need me 🙂 . But i am sure he is able to assist.

  • kinghnvn Profile Picture
    on at

    For First, you can combine your current code like -> Yes, I'm using the same the code

     

    If
    (
    !IsBlank(LookUp(DeskBooking,Employee.Email = UserInfo.Email && MySlotTime)), DisplayMode.Disabled,
    !IsBlank(LookUp(DeskBooking,MySlotTime && Title = MainGallery.Selected.Title)), DisplayMode.Disabled
    )

     

    For Second, I have tried to use the code but it's not working

     

    Behavior function in a non-behavior property. You can't use this propert to change values elsewhere in the app.

    Delegation warning. The highlighted part of this formula might not work correctly on large data sets. The "CountRows" operation is not supported by this connector.
    The function 'If' has some invalid arguments.

    --

     

    The Book button / Visible:

     

    UpdateContext({IsMorethan2Bookings : false});
    ForAll(DateDiff(Calendar_1.StartDate, Calendar_1.EndDate),
    If(CountRows(
    Filter(OfficeBooking_1,
    Employee.Email = UserInfo.Email && FromDate = DateAdd(Calendar_1.StartDate, ThisRecord.Value,Days)
    )) >= 2,UpdateContext({IsMorethan2Bookings : true});
    ) //If
    ); //ForAll

    If(IsMorethan2Bookings, Notify("You can't book more than two desks in single day"),
    Patch(.....)
    )

     

    kinghnvn_0-1640242610182.pngkinghnvn_1-1640242687959.png

     

  • kinghnvn Profile Picture
    on at

    Hi @AJ_Z 

     

    I just noticed that @StalinPonnusamy has popped in to offer assistance reply @AJ_Z to me if you still need me 🙂 . But i am sure he is able to assist. -> My question is open for everyone ^^. thank you so much, I'm still need your help.

     

    Step Two: change the label's Visible property to: CountRows(Filter(Datasource,User.Email = User().Email && RelatedDate Today()))>=2

    -> I have tried your code as below

     

    CountRows
    (Filter
    (Datasource,
    Employee.Email = UserInfo.Email &&
    DateValue(Text(selectedEndDate,DateTimeFormat.ShortDate)) = FromDate)) < 1

     

    but I'm getting the message:

     

    Delegation warning. The highlighted part of this formula might not work correctly on large date sets. The "CountRows" operation is not supported by this connector.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard