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

Power Apps - Select Max Row for Each Group

Hello,

 

I have a table with CompanyName, Year, and Qtr (plus other fields but these are the ones I am interested in using). I am displaying a Gallery List, filtered companies for this year, then sorted CompanyName ascending and Qtr descending. The .Items statement is: 

 

SortByColumns(GroupBy(Filter('Sharepoint Co List', FY=varFY), "CompanyName", "Qtr", "GroupbyData"),"CompanyName",Ascending, "Qtr",Descending)

 

Which displays the following:

 

CompanyName   Year  Qtr

ABC Company     19     3

ABC Company     19     2

ABC Company     19     1

Bob's Co              19     2

Bob's Co              19     1

Dave's Co            19     1

Sue's Co              19     4

Sue's Co              19     1 

 

However, I only need to bring in the record with the latest Qtr for each unique CompanyName group. This would result in only the 'bolded' records being brought into the Gallery. Any thoughts/ideas on how to do this? TIA

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @luvagoldenk9 ,

According to your description, I've made a similar test.

Try this formula:

AddColumns(
GroupBy(tablename,"CompanyName","test"),
"MaxQtr",Max(test,Qtr),
"Year",LookUp(test,Qtr=Max(test,Qtr),Year)
)

Please replace the tablename with the name that you use.

 

 

Best regards,

Community Support Team _ Phoebe Liu

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Community Support
Community Support

Hi @luvagoldenk9 ,

According to your description, I've made a similar test.

Try this formula:

AddColumns(
GroupBy(tablename,"CompanyName","test"),
"MaxQtr",Max(test,Qtr),
"Year",LookUp(test,Qtr=Max(test,Qtr),Year)
)

Please replace the tablename with the name that you use.

 

 

Best regards,

Community Support Team _ Phoebe Liu

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

THANK YOU Phoebe for your solution! It worked perfectly and I really appreciate your assistance!!!!

Could someone please help me understand what 'test' represents in the solution? Is that a new column?

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (77,122)