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 / Evaluate dates in Gall...
Power Apps
Answered

Evaluate dates in Gallery, and sort by soonest date...

(0) ShareShare
ReportReport
Posted on by 802

Hi there,

 

I have three labels which show different dates in a Gallery from my Dataverse table. 

 

These dates are in the format of dd/mm/yyyy. 

 

What I want is the Gallery to sort items based on the soonest date from across the three dates (so if the dates are 26/04/2022, 24/04/2022 and 28/04/2022, it will sort as 24/04/2022 as the earliest). How can I do this?

 

My labels showing the dates are

 

ThisItem.'Dateone'
ThisItem.'Datetwo'
ThisItem.'Datethree'

 

Thanks,

K.

 

Categories:
  • rubin_boer Profile Picture
    4,843 Super User 2024 Season 1 on at

    hi @Kosenurm 

     

    Consider the following:

    Add a column to your data "EarliestDate" in this example and sort your dates in a table. sort the gallery's datasource by this column ascending.

     

    below is an example.

    Sort(
     AddColumns(
     colDemo,
     "EarliestDate",
     First(
     Sort(
     [
     dateOne,
     dateTwo,
     dateThree
     ],
     Value,
     Ascending
     )
     ).Value
     ),
     EarliestDate,
     Ascending
    )​

     

    hope it helps,

    R

     

  • Kosenurm Profile Picture
    802 on at

    Thanks for the reply, however, this isn't working in PowerApps, and I'm getting all sorts of errors.

     

    Do you mean I should add a column to the Dataverse entitled EarliestDate?

     

     

  • Verified answer
    rubin_boer Profile Picture
    4,843 Super User 2024 Season 1 on at

    hi @Kosenurm 

     

    AddColumns will add the column in the gallery to the existing datasource. Can you please take a screenshot of your code with the errors.

     

    in the previous post:

    colDemo = your Dataverse table

    dateOne = your Dateone

    dateTwo = your Datetwo

    dateThree = your Datethree

     

    Consider the dataverse table is the below code

    ClearCollect(
     yourDataverseTable,
     ForAll(
     Sequence(10),
     {
     id: Value,
     Dateone: Today() - RandBetween(
     1,
     10
     ),
     Datetwo: Today() - RandBetween(
     1,
     10
     ),
     Datethree: Today() - RandBetween(
     1,
     10
     )
     }
     )
    )

    This will create something like this in a gallery

    rubin_boer_0-1650526178629.png

     

    Adding a column to this gallery (you can do this by adding it to a collection as well) will have the earliest date

    rubin_boer_1-1650526458880.png

     

    Now you can sort you gallery by the added column, EarliestDate

    rubin_boer_2-1650526579166.png

     

    As you can see the gallery is now sorted by the earliest date of the three in ascending order.

     

    I hope this is more clearer and it helps a bit,

    R

     

     

     

  • Kosenurm Profile Picture
    802 on at

    Thank you this is excellent and worked. I will mark as resolved. One final question, I have a button in the Gallery which is an Edit button - OnSelect of this is 

     

     

    Set(selectedItem, ThisItem)

     

     

    There is a Form below where some users can edit the Dataverse record. But the Form's Item property (which is just 'selectedItem') is now displaying...

     

    "Invalid formula. Expected a value compatible with 'DataSource'"

     

    This error wasn't there before. Is there something I am missing?

     

    Thanks

    K.

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

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard