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 / Struggling to get corr...
Power Apps
Suggested Answer

Struggling to get correct code syntax to configure OnSelect property (Canvas)

(2) ShareShare
ReportReport
Posted on by 19
Goal:
I am attempting to build a Vehicle Rental System in Canvas.
 
When the user selects a BeginDate and EndDate via the form, and then clicks "Search Available Vehicles," I would like for all vehicles available during that timefrime to populate in the gallery on the form.
 
I am currently running into issues determining the correct code syntax for the OnSelect property correctly. Could someone please take a look or direct me to resources which could help? Please see below.
 
OnSelect Code:
 
ClearCollect(
    colUnavailableCars, // Temporary Collection to store IDs of unavailable cars
    Filter(
        'Rentals Calendar',
        BeginDate <= EndDate_DatePicker.SelectedDate && EndDate >= BeginDate_DatePicker.SelectedDate // Check for date overlaps. VERY IMPORTANT!
    )
);
ClearCollect(
    colAvailableCars, // Temporary Collection to store available cars
    Filter(
        Cars,
        !(CarID in colUnavailableCars.CarID) // Check if CarID is NOT in the list of unavailable CarIDs
    )
);
 
 
 
Assumptions:
  • 'Vehicle List' is the name of your SharePoint list containing vehicle information.
  • 'Rentals Calendar' is the name of your SharePoint list containing rental information.
  • BeginDate_DatePicker is the name of your date picker control for the rental start date.
  • EndDate_DatePicker is the name of your date picker control for the rental end date.
  • CarIDTitle is the internal name of the CarID column in the 'Vehicle List'. Verify this in SharePoint list settings!
  • CarID is the name of the CarID column in the Rentals list.
  • You want to display the available cars in a gallery named AvailableCars_Gallery.
  • The CarID column in the Rentals List contains the ID of the Car.
  • BeginDate is the column name in the Rentals Calendar for existing reservations.
  • EndDate is the column name in the Rentals Calendar for existing reservations.
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
     
    Apologies but other than your Delegation warning, what exact error are you seeing? I do not see anything wrong with what you have. I mean we can fix your delegation issue, but what isn't happening exactly?
  • Suggested answer
    sumitkp Profile Picture
    6 on at
    Hi. The Not..In isn't supported in Power Apps. 
     
    I have implemented a similar thing but using a lookup column.
    • I have a table 'SumitCarRentals' which has columns: CarID, BeginDate and EndDate.
    • I have another table 'SumitCarDetails' which has columns: Name, CarID (LookUp Column to SumitCarRentals table), CarType.
     
    Schema for SumitCarDetails table:
     
     
    Schema for SumitCarRentals table:


     
    In the below image, I have a vertical gallery which display all the available cars after the StartDate.

    In the gallery it shows the cars which are booked for the period shown. The Search button is for the new booking after the end date of current booking.
     
    The formula for OnSelect would be: 
    ClearCollect(colAvailableCars, Filter(SumitCarDetails, CarID.EndDate <= Start_DatePicker.SelectedDate));

    I hope this solves your issue.
     
     
  • Suggested answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    Firstly Not() certainly is available in Power Apps - it is just not Delegable with SharePoint. If you have less than 500 records inside the date filter, this will work. It also "masks" the Delegation problem as it is not relevant on numbers less than your Data Row Limit (which you can increase to 2,000 if required).
    With(
       {
          _Unavailable,
          Filter(
             'Rentals Calendar',
             BeginDate <= EndDate_DatePicker.SelectedDate && EndDate >= BeginDate_DatePicker.SelectedDate 
          ),
          _Cars: Cars
       },
       ClearCollect(
          colAvailableCars,
          Filter(
             _Cars,
             !(CarID in _Unavailable.CarID)
          )
       )
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn   
     
  • CU06061114-0 Profile Picture
    19 on at
    I wanted to add that ALL vehicles are showing up, rather than only the filtered ones. Only the available vehicles should show, not all of them!
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at
    The code I posted should exlude any car where the CarID in colAvilableCars is also in the CarID of 'Rentals Calendar' between those dates.

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