2nd or 3rd most common number formula in filtered column

honkin

Active Member
Joined
Mar 20, 2012
Messages
371
Office Version
  1. 2016
Platform
  1. MacOS
I have an array formula which lets me know the most frequent number in an autofiltered column. It's just handy to have at the bottom of particular columns to let me know the most common number above, even after filtering

This is the array formula

Rich (BB code):
{=INDEX(AN18:AN36169,MATCH(TRUE,FREQUENCY(IF(SUBTOTAL(3,OFFSET(AN18,ROW(AN18:AN36169)-
MIN(ROW(AN18:AN36169)),,,)),MATCH(AN18:AN36169,AN18:AN36169,0)),ROW(AN18:AN36169)-
MIN(ROW(AN18:AN36169))+1)=MAX(FREQUENCY(IF(SUBTOTAL(3,OFFSET(AN18,ROW(AN18:AN36169)-
MIN(ROW(AN18:AN36169)),,,)),MATCH(AN18:AN36169,AN18:AN36169,0)),ROW(AN18:AN36169)-MIN(ROW(AN18:AN36169))+1)),0))}

What I am wanting to know is can this formula be tweaked at all so it gives possibly the top 2 or even 3 numbers, or is it limited to just finding the single most frequent? I'm not look for a macro at all, as just need the result to sit at the bottom of the column.

Thanks in advance
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
First (replaces your existing mega long formula)
Excel Formula:
=AGGREGATE(13,5,AN18:AN36169)
Second
Excel Formula:
=MODE.SNGL(IF(SUBTOTAL(102,OFFSET(AN18,ROW(AN18:AN36169)-ROW(AN18),0))=1,IF(AN18:AN36169<>XXX,AN18:AN36169)))
Third
Excel Formula:
=MODE.SNGL(IF(SUBTOTAL(102,OFFSET(AN18,ROW(AN18:AN36169)-ROW(AN18),0))=1,IF(AN18:AN36169<>XXX,IF(AN18:AN36169<>YYY,AN18:AN36169))))

Note that the second and third formulas contain references XXX which need to be edited so that they look at the cell holding the first formula.
The third formula also contains a reference YYY which needs to be edited to look at the cell holding the second formula.

In theory you could keep the chain going for 4th, 5th, etc. but the formulas will be very slow to calculate.
 
Upvote 0
Solution
First (replaces your existing mega long formula)
Excel Formula:
=AGGREGATE(13,5,AN18:AN36169)
Second
Excel Formula:
=MODE.SNGL(IF(SUBTOTAL(102,OFFSET(AN18,ROW(AN18:AN36169)-ROW(AN18),0))=1,IF(AN18:AN36169<>XXX,AN18:AN36169)))
Third
Excel Formula:
=MODE.SNGL(IF(SUBTOTAL(102,OFFSET(AN18,ROW(AN18:AN36169)-ROW(AN18),0))=1,IF(AN18:AN36169<>XXX,IF(AN18:AN36169<>YYY,AN18:AN36169))))

Note that the second and third formulas contain references XXX which need to be edited so that they look at the cell holding the first formula.
The third formula also contains a reference YYY which needs to be edited to look at the cell holding the second formula.

In theory you could keep the chain going for 4th, 5th, etc. but the formulas will be very slow to calculate.
Cheers Jason

Great to see that shorter code. The other always looked so cumbersome, but since it worked, I never bothered to look further. I tested yours and it seems to work fine as I filter.

The other 2 give no joy at all; both sit there with #VALUE! in the respective cells. The XXX reference is AN36171, which is where the formula for 1st is and the YYY reference is AN36172, which is where the formula for 2nd is.

Any thoughts on what may be causing the issue with those last 2?
 
Upvote 0
One other thought besides array confirmation, is there valid data to return?

If there is only 1 number in the visible range that appears more than once then the second and third will return errors. With the size of the range, I made the assumption that there would be a sufficient number of repeated values for the formula to work correctly.
 
Upvote 0
Did you array confirm them?
No Jason, sorry, there wasn't a mention of them as array formulas so didn't do it that way. Just set them as array formulas and they appear to be working fine.

Thanks so much for your help

cheers
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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