Return top x based on criteria

rushford1

New Member
Joined
Apr 13, 2010
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I need the sheet "Top 5" to list the top 5 records from the sheet named in cell C2. The returned top 5 records should be based on the "Amount" (column B) and include only the records that fall into the fiscal quarter mentioned in cell C3 on the sheet "Top 5". If there are duplicate "Amount" values, they should be listed in the order they appear on the second sheet.

Is this possible? Thanks in advance!


Snag_102f1b12.png
Snag_102f5164.png
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try:

Book1
ABC
1
2Sheet Name23Aug2024
3Fiscal Year and Quarter2024 Q3
4
5
6Top #CompanyAmount
71company E500000
82company F60000
93company C48000
104company A7059
115
12
Top 5
Cell Formulas
RangeFormula
B7:C10B7=LET(table,INDIRECT("'"&C2&"'!A6:C100"),date,INDEX(table,0,1),year,LEFT(C3,4)+0,month,RIGHT(C3,1)*3-2,ty,YEAR(date),tm,MONTH(date),f,FILTER(table,(ty=year)*(tm>=month)*(tm<=month+2)),s,SORT(f,2,-1),INDEX(s,SEQUENCE(MIN(5,ROWS(s))),{3,2}))
Dynamic array formulas.


This assumes your fiscal quarters are the same as the yearly quarters, e.g. Q3 is July, August, September. This also assumes that the number of rows on your data sheets only go down to row 100, but that is easily changed, change the C100 to Cxxx where xxx is the bottommost possible row.
 
Upvote 1
Solution
Try:

Book1
ABC
1
2Sheet Name23Aug2024
3Fiscal Year and Quarter2024 Q3
4
5
6Top #CompanyAmount
71company E500000
82company F60000
93company C48000
104company A7059
115
12
Top 5
Cell Formulas
RangeFormula
B7:C10B7=LET(table,INDIRECT("'"&C2&"'!A6:C100"),date,INDEX(table,0,1),year,LEFT(C3,4)+0,month,RIGHT(C3,1)*3-2,ty,YEAR(date),tm,MONTH(date),f,FILTER(table,(ty=year)*(tm>=month)*(tm<=month+2)),s,SORT(f,2,-1),INDEX(s,SEQUENCE(MIN(5,ROWS(s))),{3,2}))
Dynamic array formulas.


This assumes your fiscal quarters are the same as the yearly quarters, e.g. Q3 is July, August, September. This also assumes that the number of rows on your data sheets only go down to row 100, but that is easily changed, change the C100 to Cxxx where xxx is the bottommost possible row.
Eric W - That is some crazy magic right there! THANK YOU SO MUCH!
 
Upvote 0
@Eric W - How would I get a total of the Amount (not filtered to the top 5) for the sheet mentioned in cell C2 and based on the fiscal quarter filter in cell C3 of the Top 5 sheet?
Robin
 
Upvote 0
With the data sheet like this:

Book1
ABC
1
2
3
4
5Date Amount Company
69/3/2024$ 7,059.00Company A
73/15/2024$ 410,000.00Company B
88/20/2024$ 48,000.00Company C
912/5/2024$ 55,000.00Company D
107/5/2024$ 500,000.00Company E
118/20/2024$ 60,000.00Company F
126/1/2024$ 400,000.00Company G
1311/25/2024$ 60,000.00Company H
1411/25/2024$ 390,000.00Company I
159/1/2025$ 500,000.00Company J
16
23Aug2024


You can get the total amount like this:

Book1
ABC
1
2Sheet Name23Aug2024
3Fiscal Year and Quarter2024 Q3
4Total Amount$ 615,059.00
5
6Top #CompanyAmount
71Company E$500,000.00
82Company F$ 60,000.00
93Company C$ 48,000.00
104Company A$ 7,059.00
115
12
Top 5
Cell Formulas
RangeFormula
C4C4=LET(sc,INDIRECT("'"&C2&"'!B6:B100"),dc,INDIRECT("'"&C2&"'!A6:A100"),sd,DATE(LEFT(C3,4),RIGHT(C3,1)*3-2,1),ed,EOMONTH(sd,2),SUMIFS(sc,dc,">="&sd,dc,"<="&ed))
B7:C10B7=LET(table,INDIRECT("'"&C2&"'!A6:C100"),date,INDEX(table,0,1),year,LEFT(C3,4)+0,month,RIGHT(C3,1)*3-2,ty,YEAR(date),tm,MONTH(date),f,FILTER(table,(ty=year)*(tm>=month)*(tm<=month+2)),s,SORT(f,2,-1),INDEX(s,SEQUENCE(MIN(5,ROWS(s))),{3,2}))
Dynamic array formulas.


Same caveat as before, change the bottom maximum row from 100 to whatever it really is.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top