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 / Filter gallery using G...
Power Apps
Answered

Filter gallery using GroupBy

(0) ShareShare
ReportReport
Posted on by 603

Hi 

 

I want to show the below list in a gallery in Powerapps, group by EventUniqueID.

 

For EventUniqueID=1, there are 3 records currently. In Powerapps gallery, it should show only the record which is upcoming in few days (i.e. 29 Jan 2023). It should not show 10 Jan 2023 record, since its already passed. On 30 Jan 2023, it should show the next record for EventUniqueID=1, i.e. 02 Feb 2023. 

 

Any idea how to achieve this?

 

Iantaylor2050_0-1673881720964.png

 

 

 

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

    Hi @Iantaylor2050,

     

    A possible way to achieve this is by using the following structure in the Items property of your gallery:

    With(
     {
     uniqueID: Distinct(
     LISTNAME,
     EventUniqueID
     )
     },
     ForAll(
     uniqueID As CurrentID,
     First(
     Sort(
     Filter(
     LISTNAME,
     EventUniqueID = CurrentID.Result &&
     'Start Date and Time' > Now()
     ),
     'Start Date and Time',
     Ascending
     )
     )
     )
    )

    This will retrieve the next event for each unique event ID. Please adjust the names within the code where necessary (e.g. LISTNAME).

     

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

    Thanks!

  • Iantaylor2050 Profile Picture
    603 on at

    Hi @LaurensM 

     

    I want to sum up the number of openings available column, groupby EventUniqueID field and display in a gallery textbox for each events. 

     

    For EventUniqueID=11, number of openings should be displayed as 15 (7+8)

     

    Also, if the date has already passed for an event, number of openings should be excluded for that ID.  i.e. For EventUniqueID=1, since the 1st event, 10 Jan 2023 has already passed, number of openings should be displayed only as 17 (8+9). Any idea how to achieve this? Have included screenshot below

     

    Iantaylor2050_0-1674058047683.png

     

     

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Iantaylor2050,

     

    The Label within your gallery would have the following code in the Text property:

    Sum(
     Filter(
     LISTNAME, 
     EventUniqueID = ThisItem.EventUniqueID && 
     'Start Date and Time' > Now()
     ),
     'No of Openings'
    )

    Adjust the Listname and column name where necessary.

     

    As a note: you could also use an AddColumns() in the gallery's Items property to create a new column with that value and reference the newly created column instead.

     

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

    Thanks!

  • Iantaylor2050 Profile Picture
    603 on at

    Hi @LaurensM 

     

    I am using the above code to display the upcoming events in ascending order. Gallery Items property is set to below piece of code

     

    With(
     {
     uniqueID: Distinct(
     LISTNAME,
     EventUniqueID
     )
     },
     ForAll(
     uniqueID As CurrentID,
     First(
     Sort(
     Filter(
     LISTNAME,
     EventUniqueID = CurrentID.Result &&
     'Start Date and Time' > Now()
     ),
     'Start Date and Time',
     Ascending
     )
     )
     )
    )

     

    My SharePoint list contains below items, however powerapp gallery shows wrong ordering. The items with Start date and time as 02 Feb 2023 is shown first, when I have items dated Jan 30 and Jan 31 ordered 3rd and 4th. May I know why this is happening?

     

    Iantaylor2050_0-1674406611099.png

     

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

    Thanks for reaching out @Iantaylor2050.

     

    See my response on your new topic.

     

    Since we started a new topic, would it be possible to close this one by accepting a solution.

    Thanks!

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