cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sasrsc
Resolver II
Resolver II

Min/Max Dates for a collection

This is something I am struggling with....
I have a a collection, filter, sort by, add columns in one step that works fine.
I then want to grab the min/max date from the Start variable.
So I decided to sort it again when I set the variable...

sasrsc_0-1602003473762.png

 

ClearCollect(ReportingRequiredCollection,SortByColumns(
AddColumns(
Filter(ComplianceApproval,Reporting.Value="Yes"),

"isChoosen",
false,
"TravelerName",
LookUp(CompliancePassengers,ID=PaxID,Title),
"Email",
LookUp(CompliancePassengers,ID=PaxID,Email),
"Nationality",
LookUp(CompliancePassengers,ID=PaxID,Nationality),
"Company",
LookUp(CompliancePassengers,ID=PaxID,Company),
"GovOfficial",
LookUp(CompliancePassengers,ID=PaxID,GovOfficial),
"GovOwned",
LookUp(CompliancePassengers,ID=PaxID,GovOwned),
"GovBoard",
LookUp(CompliancePassengers,ID=PaxID,GovBoard),
"AcceptJetRide",
LookUp(CompliancePassengers,ID=PaxID,AcceptJetRide),
"ComplianceComplete",
LookUp(CompliancePassengers,ID=PaxID,ComplianceComplete),
"ComplianceTripPurpose",
LookUp(CompliancePassengers,ID=PaxID,ComplianceTripPurpose),
"Routing",
LookUp(ComplianceTrips,ID=TripId,Routing),
"Start",
LookUp(ComplianceTrips,ID=TripId,Start),
"ApproverEmail",
User().Email
),"Start",Descending)

);
Set(StartDate,Last(Sort(ReportingRequiredCollection,Start,Descending)));

I'm expecting StartDate to be 10/27/2020 but it's resolving as a "record" and I don't see a value like I do in the reportingrequiredcollection.start value.

2 REPLIES 2
rsaikrishna
Dual Super User
Dual Super User

@sasrsc 

 

You do not need need to sort multiple times. You can use First and Last records from the collection already sorted by the StartDate column.

 

If the collection ReportingRequiredCollection already sorted by Start date in Ascending order, then I will use following formulas to create variables:

 

Minimum Start Date:
Set(varMinStartDate,First(ReportingRequiredCollection).Start);

Maximum Start Date:
Set(varMinStartDate,Last(ReportingRequiredCollection).Start);

 

Now, if we assume that the collection ReportingRequiredCollection is not sorted by Start date.

 

ClearCollect(colSortedByStartDate, Sort(ReportingRequiredCollection,Start,Ascending))

Minimum Start Date:
Set(varMinStartDate,First(colSortedByStartDate).Start);

Maximum Start Date:
Set(varMinStartDate,Last(colSortedByStartDate).Start);

 

I hope above reply will help you.

 

Regards

Krishna Rachakonda

If this reply helped you to solve the issue, please mark the post as Accepted SolutionMarking this post as Accepted Solution, will help many other users to use this post to solve same or similar issue without re-posting the issue in the group. Saves a lot of time for everyone.

I tried doing that and I get this incompatible type issue...

sasrsc_0-1602205903406.png

 

Set(StartDate,Last(ReportingRequiredCollection).Start);

It does not complain when I resort it and do my original statement

 

sasrsc_1-1602205943788.png

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,329)