cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rebeccak
Helper III
Helper III

Collection--GroupBy---Add Columns---Earliest Date

I want to collect data by "Type", group by "Site" and add a column "Earliest Due Date". I am collecting and grouping properly but i don't know how to get the earliest due date. 

 

ClearCollect(colGroupType,AddColumns(GroupBy(dbo.data, "Site","Total"),"EarliestDueDate",   ------This is where im stuck. Everything i do is not correct

 

Type          Site          Due Date

1                Home      1/1/2019

1                Home      1/10/2019

1                Home      1/20/2019

1                Home      1/12/2019

2                Home      1/1/2019

2                Home      1/1/2019

1                Away        1/3/2019

2                Away        1/2/2019

2                Home       1/2/2019

2                Home       1/24/2019

2                Home       1/23/2019

2                Home       1/22/2019

2                Home       1/21/2019

 

Collection

Type            Site          Earliest due Date

1                  Home       1/1/2019

1                  Away        1/3/2019

2                  Home       1/1/2019

2                  Away        1/2/2019

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Rebeccak 

Sure thing...

You mentioned grouping by type and site, but your formula didn't seem to account for the type.  So, here is the formula with grouping for type, and site with earliest date for the items.

NOTE: I based this formula off of your sample with the following assumption - the Due Date column was a Date column - not a text column.

ClearCollect(colGroupType, 
    AddColumns(
        GroupBy(dbo.data, "Type", "Site", "Total"),
     "EarliestDueDate", Min(Total,DueDate))
) )

If you want to store the earliestdate in your collection as a formatted date (rather than the date value in the above formula), then change the "EarliestDueDate" calculation to: Text(Min(Total,DueDate), "[$-en-US]mm/dd/yyyy")  

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

1 REPLY 1
RandyHayes
Super User
Super User

@Rebeccak 

Sure thing...

You mentioned grouping by type and site, but your formula didn't seem to account for the type.  So, here is the formula with grouping for type, and site with earliest date for the items.

NOTE: I based this formula off of your sample with the following assumption - the Due Date column was a Date column - not a text column.

ClearCollect(colGroupType, 
    AddColumns(
        GroupBy(dbo.data, "Type", "Site", "Total"),
     "EarliestDueDate", Min(Total,DueDate))
) )

If you want to store the earliestdate in your collection as a formatted date (rather than the date value in the above formula), then change the "EarliestDueDate" calculation to: Text(Min(Total,DueDate), "[$-en-US]mm/dd/yyyy")  

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,695)