Filter & Sequence Together

BrettOlbrys1

Board Regular
Joined
May 1, 2018
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Is it possible to use Filter & Sequence together in one formula?

I have 1,000 rows of data in columns A, B, C, and D.

Column A = Customer Name
Column B = Market Segment
Column C = Qty
Column D = Product

I want to return the Top 5 rows of data based on QTY (greatest to least) and limit it to 5 rows, even if there are duplicate qty's. Right now, I have the following formula:

D2 = Product Y

SORT(FILTER(CSR_Activations,(CSR_Activations[Qty]>=(LARGE(IF(CSR_Activations[Product]=D2,CSR_Activations[Qty]),5)))*(CSR_Activations[Product]=D2)),3,-1)

When there are duplicate qty's that bring my total line count to greater than 5, I get a SPILL error because I have other tables below this section. I know with the SEQUENCE command I can limit it to 5 rows, but I have been unable to combine the two functions so that I only return the Top 5 rows with data in columns A, B, C, and D.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I figured out that this formula works:

INDEX(SORT(FILTER(CSR_Activations,(CSR_Activations[Qty]>=(LARGE(IF(CSR_Activations[Product]=D2,CSR_Activations[Qty]),5)))*(CSR_Activations[Product]=D2)),3,-1),SEQUENCE(5),{1})

But, I need to have this formula in each column and change the last "1" to a "2", "3", and "4" for columns A, B, C, and D.

Question, is there a formula that doesn't require me to change the last number?
 
Upvote 0
Perhaps along these lines?

ABCDEF
1DataFilter5
2q1r99
3w15g88
4a2t77
5s44s44
6d44d44
7f44
8g88
9r99
10t77
11
Sheet1
Cell Formulas
RangeFormula
E2:F6E2=LET(d,B2:C10,N,F1,s,SORT(d,2,-1),FILTER(s,SEQUENCE(ROWS(d))<=N))
Dynamic array formulas.

Edit: Or a little more succinctly: =LET(N,F1,s,SORT(B2:C10,2,-1),FILTER(s,SEQUENCE(ROWS(s))<=N))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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