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

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
v-yutliu-msft
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
v-yutliu-msft
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.

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
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (5,057)