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 / Cannot make my Gallery...
Power Apps
Answered

Cannot make my Gallery Filter work on a Many to One relationship between 2 SharePoint Microsoft Lists with Datepicker as filter criteria - Help needed

(0) ShareShare
ReportReport
Posted on by 12

Hello Power Apps Community,

 

I am stuck with my designed reservation powerapp. It can go in production if i can solve the problem that i face with an important Gallery Filter. I tried to modify it several times, but always fail with the expected result.

 

In this example: i want to select a free date to reservate an laptop between 21/02/2024 till 23/02/2024.

In the Gallery items are 4 free laptop records where i can choose from. but also record laptop ID 6, that already is reserved in the reservationlist 2 times under ID 134 and ID 135

 

These are reservations for the same Laptop (via a lookup column field to the other list "LoanList")

The problem is, whenever i change the start or enddate in the datepicker: does it still give record ID 134 as available reservation

Fenvy_4-1708087941020.png

 

Here it should give only the records (8, 12, 16, 18) that are still available and not reserved in the reservationList as results, since record Laptop ID 6 from the LoanList refers to an existing reservation in LaptopReservations List with ID 134 the same device as record 135, reservated on 2 different time ranges

the startdate 21/02/2024 is the Enddate of the reservationrecord 135 from the same laptop with lookup ID 6, so it shouldn't show the other record 134  as well.

Fenvy_5-1708088314940.png

 

An overview from the Parent List "LoanList"

Fenvy_6-1708089191670.png

Code structure in the Powerapp

The filter in this gallery.items is:

 

 

 

 With(
 {wReservations: LaptopReservations};
 Filter(
 LoanList;
 Purpose.Value = "Mobile Office";
 'Id (ID)' in Filter(
 wReservations;
 startDatePicker.SelectedDate > EndDate && EndDatePicker.SelectedDate > EndDate 
 || 
 EndDatePicker.SelectedDate < StartDate
 ||
 startDatePicker.SelectedDate > EndDate && startDatePicker.SelectedDate > StartDate
 ||
 startDatePicker.SelectedDate < StartDate && EndDatePicker.SelectedDate < StartDate
 ).NID || Not('Id (ID)' in LaptopReservations.NID)
 )
 )

 

 

 

The column 'NID' is from type "Number", since i need it to filter on, somehow my filter fails completely when i try to filter on the lookup field.Id in LaptopReservations List.

With a Automated flow does the NID field gets populated with the laptop_ID lookup number after a item is created in this Microsoft List (this is not relevant information but i want to try to give all details that can help)

 

Can you help or give me advice in how i need to solve this filter problem?

 

Kind regards,

Fenvy

 

Categories:
  • renatopc84_ch Profile Picture
    228 on at

    Hi @Fenvy 

    i had a similar issue, now I should put everything on a whiteboard to say you exactly the solution, anyway is in the Filter conditions. You use all “||”, so OR condition, as I understood from your use case, you should group some of the OR conditions under AND (“&&”) groups

  • renatopc84_ch Profile Picture
    228 on at

    more specific I assume this should be the issue:

     

    EndDatePicker.SelectedDate < StartDate

     

    You have this condition as OR of all others

  • Verified answer
    Fenvy Profile Picture
    12 on at

    Hello @renatopc84_ch ,

     

    Thank you very much for your input about the use for "GroupBy", it started to let me rethink about how i created my filters.

     

    With this i have searched about the syntax for Combining  Filter with GroupBy to filter on the data from a nested groupby table.

    I found the solution in this post: Solved: Filtering a gallery if all items in a groupby equa... - Power Platform Community (microsoft.com)

    And modified it slightly for my filter criteria.

     

    My new Gallery Items is:

    Filter(
     AddColumns(
     SortByColumns(
     GroupBy(
     LaptopReservations;
     "NID";
     "GroupByNID"
     );
     "NID";
     SortOrder.Ascending
     );
     "Count";
     !CountRows(GroupByNID);
     "CountForDateRange";
     CountIf(
     GroupByNID;
     startDatePicker_4.SelectedDate > StartDate && startDatePicker_4.SelectedDate > EndDate
     ||
     EndDatePicker_4.SelectedDate < StartDate && EndDatePicker_4.SelectedDate < EndDate
     )
     );
     (CountRows(GroupByNID) = CountIf(
     GroupByNID;
     startDatePicker_4.SelectedDate > StartDate && startDatePicker_4.SelectedDate > EndDate
     ||
     EndDatePicker_4.SelectedDate < StartDate && EndDatePicker_4.SelectedDate < EndDate
     ))
    )

    Results in: If the count from total record in the groupby table where i perform the filter on, is not the same as the count without filter on it,  (in other words "Count is true" then that specific record will not be shown.

     

    Fenvy_0-1708530973578.png

     

    If startdatepicker is on 21/02/2024, the gallery does not shown the groupby Record ID 6

    Fenvy_1-1708531149714.png

    Since 21/02/2024 is the Enddate from a reservation on this laptop ID 🙂

     

    But this shows only the Reservations, and not the Loanlist from laptops, so i need to work this out to combine the correct filter groupby code with showing it as a part in a gallery from LoanList items.

     

    But thank you again for the time you spent to help me out with this filtering issue.

     

    Kind regards,

    Fenvy

     

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 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard