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 / Setting visibility bas...
Power Apps
Unanswered

Setting visibility based on Time and Button Name

(0) ShareShare
ReportReport
Posted on by 338

Hello, Im looking for and advise in order to try and build some kind of a dashboard for  booking app that Im building.

So I have the following situation:

app question.png

 

This the booking thingy I have as of now. Based on the Button Self Name and Todays date its filtering the collection and if bigger than one sets the display mode to disabled. However there are 12 slots for about 5 different activities that colleagues can choose from and seeing all the slots its a little bit confusing and thus the reason I want to simplify it. What I want to achieve is based on the time now to show me only the current booking and the upcoming one(No matter if they are subsequent, just to show the next booked one) . The source is sharepoint list. Is this possible? Thank you in advance for the help.

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @SectorOMEGA,

     

    You could filter the list to only display the bookings that are currently active or later - sorted in ascending order. From this list we will only display the first 2 records:

     

    FirstN(
     Sort(
     Filter(
     ListName,
     //Either the booking is currently active, or it still has to occur
     StartDateTime <= Now() && EndDateTime > Now() || StartDateTime > Now() && EndDateTime > Now()
     ),
     //Sort by startdatetime field ascendingly (currently active one first)
     StartDateTime
     ),
     //Only display the currently active one and next in line
     2
    )

     

    With this set-up I expect that each record has a DateTime field for both the start and end time. Additionally, we only expect 1 currently active booking - otherwise you may display 2 currently active ones.

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • SectorOMEGA Profile Picture
    338 on at

    @LaurensM Thank you so much. This one looks perfect, however, I do not have start and end time in separate fields. I use the button labels to determine the chosen slot ie in SP column for chosentimeslot I have: 12:00 - 13:00 only as text. So now Im trying to adapt the code for my situation.

  • gcmfaizan Profile Picture
    1,022 on at

    Hi @SectorOMEGA ,

    I have an Idea based on your description, you'd like to display only the current booking and the next upcoming booking based on the current time. Since you have the time slots in button labels and they are stored in SharePoint as text (e.g., "12:00 - 13:00"), you can achieve this with a combination of filtering and sorting.

    Here's how you can approach it:

     

     

     

     

    ClearCollect(
     BookingData,
     SharePointList
    )

     

     

     

    Now create a new column in your collection to convert the text time slots to actual time values. For example:

     

     

     

    ForAll(
     BookingData,
     Patch(
     BookingData,
     Defaults(BookingData),
     {
     ChosenTimeSlot: Text(
     TimeValue(Mid(ChosenTimeSlot, 1, 5)),
     "[$-en-US]hh:mm tt"
     )
     }
     )
    )

     

     

    Filter and sort the collection to get the current and upcoming booking:

     

     

    Set(
     CurrentTime,
     Now()
    );
    ClearCollect(
     FilteredBookings,
     Sort(
     Filter(
     BookingData,
     ChosenTimeSlot >= CurrentTime
     ),
     ChosenTimeSlot,
     Ascending
     )
    )

     

     

    Now, you can use the FilteredBookings collection to display the current booking and the next upcoming booking.

    • For the current booking: Use First(FilteredBookings) to get the first record in the collection.
    • For the next upcoming booking: Use If(CountRows(FilteredBookings) > 1, FilteredBookings[1]) to get the second record if it exists.

     

    Please mark my post as solution if it helps you. And please don't forget to give an Appreciation Thupm Up.

    Cheers!

     

  • SectorOMEGA Profile Picture
    338 on at

     @gcmfaizan Thats looks quite good but I cannot get something in the code.

    ForAll(
     BookingData,
     Patch(
     BookingData,
     Defaults(BookingData),
     {
     ChosenTimeSlot: Text(
     TimeValue(Mid(ChosenTimeSlot, 1, 5)),
     "[$-en-US]hh:mm tt"
     )
     }
     )
    )

    throws me an error for the Patch function that cannot operate in the same datasource. Shouldn't the Patch be working with the SP itself instead of the collection? Excuse me if Im  wrong 🙂 Just trying to get my head around this 

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard