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 / Help with complex filt...
Power Apps
Answered

Help with complex filtering on gallery

(0) ShareShare
ReportReport
Posted on by 550

Hello - I am nearly there on a filtering issue and would greatly appreciate the help of anyone to point to where I'm off base. I have a gallery where the items property is filtered based on a search bar and two drop downs created using the YouTube at: https://www.youtube.com/watch?v=kLGglidmPxg

Here is the interface that is filtering my gallery of workshops based on search bar & 2 dropdown filters. It is working as expected. 

kky1_0-1673019387127.png

 

The data source of my View All Sessions dropdown  is a collection of dates (colTimeFilter) that is calculated when the app starts to determine dates within this week, month, etc. The View All Sessions dropdown determines the dates that populate in the date gallery above my workshop gallery (circled in red).

kky1_1-1673019590251.png

My current Items property of my workshop gallery is a long If statement to filter a collection of student workshops (colStudEvents) based on the search bar (tbSearchSessions_1)  & drop down controls (ddtrack & ddTimeSelection) as pasted below:

 

If(
//This is for all and all
ddtrack.Selected.FormText = "View All Tracks" And ddTimeSelection.SelectedText.Value = "View All Sessions",
Sort(
Search(
Filter(
colStudEvents,
!IsBlank(Date) && DateValue(Date) >= Today()
),
tbSearchSessions_1.Text,
"field_2",
"TrackText",
"field_5"
),
Date,
Ascending
),
//This is for all tracks and selected time
ddtrack.Selected.FormText = "View All Tracks" And ddTimeSelection.SelectedText.Value <> "View All Sessions",
Sort(
Search(
Filter(
colStudEvents,
DateValue(Date) >= ddTimeSelection.Selected.StartDate && DateValue(Date) <= ddTimeSelection.Selected.EndDate
),
tbSearchSessions_1.Text,
"field_2",
"TrackText",
"field_5"
),
Date,
Ascending
),
//This is for selected track and all dates
ddtrack.Selected.FormText <> "View All Tracks" And ddTimeSelection.SelectedText.Value = "View All Sessions",
Sort(
Search(
Filter(
colStudEvents,
DateValue(Date) >= Today() And Track.Value = ddtrack.Selected.FormText
),
tbSearchSessions_1.Text,
"field_2",
"TrackText",
"field_5"
),
Date,
Ascending
),
//This is for selected track and selected dates
ddtrack.Selected.FormText <> "View All Tracks" And ddTimeSelection.SelectedText.Value <> "View All Sessions",
Sort(
Search(
Filter (
colStudEvents,
Track.Value = ddtrack.Selected.FormText And DateValue(Date) >= ddTimeSelection.Selected.StartDate && DateValue(Date) <= ddTimeSelection.Selected.EndDate
),
tbSearchSessions_1.Text,
"field_2",
"TrackText",
"field_5"
),
Date,
Ascending
)
)

 

I would now like to incorporate an additional filter to the Items property of my workshop gallery above the ability for a user to select a date from the date gallery (gallerySessionDates_3) to further filter the workshop gallery (galleryAgenda_1).

 

How would I do that (without breaking what I've already built)?

 

Currently, the gallerySessionDates_3 consists of just a Button (Button1_4) whose OnSelect property is Select(Parent) and whose Text property is 

 

Text(
 DateValue (ThisItem.Date),
 "[$-en-US]ddd"
) & " " & Text(
 DateValue(ThisItem.Date),
 "[$-en-US]mmm"
) & " " & Day(DateValue(ThisItem.Date))

 

kky1_2-1673020149778.png

 

I've tried filtering from this OnSelect property but am getting errors in scope, which is why I'm betting I need to incorporate this filter into the workshop gallery Items property instead. 

 

Thank you to anyone who's able to point me in the right direction!

Best,

@kky1 

 

Categories:
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @kky1,

     

    Your initial filter statement can be written in a shorter manner (replace your complete If() statement by):

     

    Sort(
     Search(
     Filter(
     colStudEvents,
     //By default, only show dates in the future
     DateValue(Date) >= Today(),
     //Filter track if View All Tracks is not selected
     ddtrack.Selected.FormText = "View All Tracks" || Track.Value = ddtrack.Selected.FormText, 
     //Filter by date range if View All Sessions is not selected
     ddTimeSelection.SelectedText.Value = "View All Sessions" || (DateValue(Date) >= ddTimeSelection.Selected.StartDate && DateValue(Date) <= ddTimeSelection.Selected.EndDate)
     ),
     tbSearchSessions_1.Text,
     "field_2",
     "TrackText",
     "field_5"
     ),
     Date,
     Ascending
    )

     

    The shorter version will reduce the code duplication and make it easier to extend in the future.

     

    To add an additional date filter via the gallerySessionDates_3, we can just extend the current filter with (gallerySessionDates_3.Selected.Date = Blank() || DateValue(gallerySessionDates_3.Selected.Date) = DateValue(Date))

    This will further filter your collection by the selected date when a record is selected. (Keep in mind that your gallery might auto select the first record due to the Default property)

     

    The complete Filter() would look as follows:

     

    Sort(
     Search(
     Filter(
     colStudEvents,
     DateValue(Date) >= Today(),
     ddtrack.Selected.FormText = "View All Tracks" || Track.Value = ddtrack.Selected.FormText, 
     ddTimeSelection.SelectedText.Value = "View All Sessions" || (DateValue(Date) >= ddTimeSelection.Selected.StartDate && DateValue(Date) <= ddTimeSelection.Selected.EndDate),
     gallerySessionDates_3.Selected.Date = Blank() || DateValue(gallerySessionDates_3.Selected.Date) = DateValue(Date)
     ),
     tbSearchSessions_1.Text,
     "field_2",
     "TrackText",
     "field_5"
     ),
     Date,
     Ascending
    )

     

     

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

    Thanks!

  • kky1 Profile Picture
    550 on at

    Thank you @LaurensM ! Your code above worked as far as adding the gallery. You are also right in that the default property of that gallery was selecting the first date, so the second gallery was only showing one workshop at a time. For this reason, I decided to skip added that first date gallery to the filter. Thank you again.

     

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

#2
Mohsin Ali Profile Picture

Mohsin Ali 323

#3
WarrenBelz Profile Picture

WarrenBelz 193 Most Valuable Professional

Last 30 days Overall leaderboard