Assistance with finding top 2 repeated values based on 2 criteria (LET,UNIQUE,FILTER,TAKE,SORT,HSTACK,COUNTIF formula)

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
905
Office Version
  1. 365
Platform
  1. Windows
I am looking to pull the top 2 repeated part numbers based criteria from 2 other columns: Division and Yes/No (for a date range).

If I filter the data by Green Co. and Date Range "Yes", the top 2 part numbers are AXT455 and N21W83 by 3 and 2, however the formula I wrote is counting as a whole, not based on the criteria.
How can I fix this formula?

=LET(u,UNIQUE(FILTER(Table1[Part '#],(Table1[Falls Between Date Range]="Yes")*(Table1[Division]=$J$2))),TAKE(SORT(HSTACK(u,COUNTIF(Table1[Part '#],u)),2,-1),2))

Thank you to anyone who can help!

test.xlsm
ABCDEFGHIJKL
1Part #Return DateDivisionFalls Between Date RangeTop 2 Returned Part #'sDate Range:January 1, 2024ToFebruary 28, 2024
2N52T1721-Nov-23Blue Co.NoAXT4557DivisionGreen Co.
3AXT45522-Apr-24Green Co.NoN21X832
4AXT45528-Feb-24Green Co.Yes
5N21X8317-Jan-24Green Co.Yes
6N21X522-Aug-23Blue Co.NoExpected Answer:
7AXT45529-Aug-23Red Inc.NoAXT4553
8N21X832
9
10
11N52T2529-Feb-24Blue Co.No
12AXT45510-Jan-24Green Co.Yes
13AXT45523-Oct-23Red Inc.No
14N52T1722-May-24Red Inc.No
15N52T2510-Jan-24Blue Co.Yes
16
17N21X8315-Jan-24Green Co.Yes
18N21X525-Dec-23Blue Co.No
19T58X1722-May-24Green Co.No
20AXT4555-Jan-24Blue Co.Yes
21N21X5220-Feb-24Red Inc.Yes
22AXT45522-Feb-24Green Co.Yes
Sheet1
Cell Formulas
RangeFormula
F2:G3F2=LET(u,UNIQUE(FILTER(Table1[Part '#],(Table1[Falls Between Date Range]="Yes")*(Table1[Division]=$J$2))),TAKE(SORT(HSTACK(u,COUNTIF(Table1[Part '#],u)),2,-1),2))
D2:D7,D17:D22,D11:D15D2=IF(AND(B2>=$J$1,B2<=$L$1),"Yes","No")
Dynamic array formulas.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I believe I figured it out. Should use Countifs...

If anyone can provide feedback if this is the correct approach I would appreciate it!

=LET(u,UNIQUE(FILTER(Table1[Part '#],(Table1[Falls Between Date Range]="Yes")*(Table1[Division]=$J$2))),TAKE(SORT(HSTACK(u,COUNTIFS(Table1[Part '#],u,Table1[Division],$J$2,Table1[Falls Between Date Range],"Yes")),2,-1),2))
 
Upvote 0
An alternative is with Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Falls Between Date Range] = "Yes")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Part #", "Division"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"
 
Upvote 0
Try:
Book1
ABCDEFGHIJKL
1Part #Return DateDivisionFalls Between Date RangeTop 2 Returned Part #'sDate Range:1/1/2024To2/28/2024
2N52T1711/21/2023Blue Co.NoDivisionGreen Co.
3AXT4554/22/2024Green Co.No
4AXT4552/28/2024Green Co.Yes
5AXT4551/10/2024Green Co.Yes
6N21X528/2/2023Blue Co.NoExpected Answer:
7AXT4558/29/2023Red Inc.NoAXT4553
8N21X832
9
10
11N52T252/29/2024Blue Co.No
12AXT4551/5/2024Blue Co.Yes
13AXT45510/23/2023Red Inc.No
14N52T175/22/2024Red Inc.No
15AXT4552/22/2024Green Co.Yes
16
17N21X522/20/2024Red Inc.Yes
18N21X5212/5/2023Blue Co.No
19T58X175/22/2024Green Co.No
20N21X831/17/2024Green Co.Yes
21N21X831/15/2024Green Co.Yes
22N52T251/10/2024Blue Co.Yes
Sheet4
Cell Formulas
RangeFormula
D2:D7,D17:D22,D11:D15D2=IF(AND(B2>=$J$1,B2<=$L$1),"Yes","No")
F7:G8F7=LET( u,UNIQUE(TOCOL(Table1[Part '#],1)), c,COUNTIFS(Table1[Part '#],u,Table1[Falls Between Date Range],"Yes",Table1[Division],J2), TAKE(SORTBY(HSTACK(u,c),c,-1),2))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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