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 / Make button in a galle...
Power Apps
Unanswered

Make button in a gallery visible only for the beginning of previous week based on selected date.

(0) ShareShare
ReportReport
Posted on by 4

I am building a food ordering app and I need to show the menu for the selected date from a calendar. When the menu is posted, users should only be able to select or order next week's menu this week (current week based on selected date) between Monday - Thursday. For example, on the picture below, Monday is selected on the calendar; therefore, the select button on the gallery should not be visible for this current week. Rather, it should have been visible last week between Monday-Thursday.

Screenshot 2023-01-05 113915.png
Here is my code on the on visible property, but it is still not doing the job. Need help with this please.

code.png

 

Categories:
I have the same question (0)
  • Kosenurm Profile Picture
    802 on at

    To show or hide the button based on the current date, you can use the Today() function to get the current date, and then compare it to the selected date from the calendar and the start and end dates for the ordering window. 

     

    Example:

     

    If(
     Today() >= SelectedDate.StartOfWeek &&
     Today() < SelectedDate.StartOfWeek.AddDays(4) &&
     Today() > SelectedDate.AddDays(-7),
     true,
     false
    )
  • Amigomusa Profile Picture
    4 on at

    This is not doing the job for me. Let me state that the variable "_dateSelected" in the sample code is set to Today(). Also a user can only select one menu per given day hence the need to check if the login user has more than one record in the collection

  • iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Heya @musa_touray - ignore that code they provided, its not even valid Power Apps code, you can't just use .AddDays or .StartOfWeek from a selected date, those kinds of things are available in other languages like C#/Javascript - their code was clearly pulled from chatGPT

     

    Ok, so, getting back to your issue - do you have a column in your colMyOrders called StartDate? because you have used With to create temporary variables for these dates and so the filter will effectively not be doing anything as it will be suing the temporary With variables, not the column in the order collection, anyway, we will deal with that below.

     

    Additionally, you said you want to only allow them to select Next week's dates, as they can only select next week's food this week, but your DateAdd code is asking them to go back in time and order this week's food last week, which is of course impossible.

     

    So, let's start with your StartDate and EndDate - we want these to run Monday-Thursday for the following week, not the previous week, as we want to check that the date the user selected is next week as they cannot order food for this week, they can only order next week's food yes?

    So in my example. today is the 15th of Feb and we want the valid choices to be next week Monday to Thursday, which is the 20th to the 23rd:

    image.png

     

    Ok, so now we have a valid way to check what next week's dates are.

     

    Now we need to check, has the user ordered food for that selected day next week already, so we need to have a column in our collection that is the OrderDate (or whatever similar name you have in your collection), then we can filter by that and check if the _selectedDate falls within the Start/End date - so if there is an order on that selected date by that user then it should be invisible as they cant' order more than once per day. Then we check is the _selectedDate within the Start/End dates and make it visible if yes.

     

    With(
     {
     //These must always reference Today, as you always want them to
     // only select dates next week, regardless of what date Today is
     StartDate: DateAdd(Today(), 8 - Weekday(Today(), Monday), Days),
     EndDate: DateAdd(Today(), 11 - Weekday(Today(), Monday), Days)
     },
     If(
     //Here we check if the user has an order on that date
     CountRows(
     Filter( colMyOrders,
     OrderDate = _dateSelected,
     createdby.Email = currentUser.Email
     )
     )>0
     // Then we also check that the date falls within the valid range
     // i.e. the date selected must fall within Mon-Thurs next week
     &&
     _dateSelected >= StartDate
     &&
     _dateSelected <= EndDate,
     false,
     //Our visible condition should be that the dateis valid
     // i.e. the date selected must fall within Mon-Thurs next week
     _dateSelected >= StartDate
     &&
     _dateSelected <= EndDate,
     true,
     //If none of the above conditions are met, do not display
     false
     )
    )

     

    Here are some example tests I did, and you can find attached a proof-of-concept .msapp app that you can open up an look at from within the editor

     

    Next week Friday chosen:

    image.png

     

    Next week Tuesday chosen:

    image.png

     

    Then I chose a date where I have already got an order in my collection next week:

    image.png

     

    please make sure to check out the .msapp attached to this if yo uwant to explore the code I gave a bit more 🙂

     

    Cheers,

    Sancho

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 421

#2
WarrenBelz Profile Picture

WarrenBelz 345 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 278 Super User 2026 Season 1

Last 30 days Overall leaderboard