Return most occurring text entry from named range where three conditions met, one with wildcards

Upex

Board Regular
Joined
Dec 29, 2010
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Hi All, hope you're well.

I cannot get this formula to work and don't get anything useful from evaluation etc:

=INDEX(Theme,MODE(IF((ReceivedDate>=DATEVALUE(W7))*(ReceivedDate<DATEVALUE(Y7))*(Product="*Tin*"),MATCH(Theme,Theme,0))))

What I'm trying to do is to return the most occurring entry from the named range 'theme' where:
the date (listed in named range ReceivedDate) is greater than or equal to the date as specified in W7
and
the date is also less than the date held in Y7
and
the product name, held in a named range 'product', contains 'tin' (using wildcards as can span several - Tin hat, Tin pan, Gal tin etc.


Any ideas on how to fix or better way to do it?

Many thanks,
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Would this work?:

Excel Formula:
=LET(
ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))),
ut, UNIQUE(ft),
tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))),
t_c, HSTACK(ut, tcount),
FILTER(t_c, tcount=MAX(tcount))
)

It returns the Theme and the count for the max occurring values. If 2 or more themes appear the same number of times, it list all of them.

Book11.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1ThemeReceivedDateProduct
2a09/08/2024SometextTinSometexta2
3b09/08/2024Sometextb2
4c09/08/2024Sometext
5b01/08/2024SometextTinSometext
6a09/08/2024SometextFromTo
7a01/08/2024Sometext01/08/202410/08/2024
8b09/08/2024SometextTinSometext
9c09/08/2024Sometext
10a09/08/2024SometextTinSometext
Sheet3
Cell Formulas
RangeFormula
F2:G3F2=LET( ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))), ut, UNIQUE(ft), tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))), t_c, HSTACK(ut, tcount), FILTER(t_c, tcount=MAX(tcount)) )
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Product=Sheet3!$C$2:$C$10F2
ReceivedDate=Sheet3!$B$2:$B$10F2
Theme=Sheet3!$A$2:$A$10F2
 
Upvote 1
That works - fab - thanks so much.

Being cheeky. is there anyway to get it to put the count volume underneath the theme rather to its right? Or to ditch the value and just leave the theme (the value being right is in the way!
 
Last edited:
Upvote 0
Can you post a sample of the data that shows the problem.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
That works - fab - thanks so much.

Being cheeky. is there anyway to get it to put the count volume underneath the theme rather to its right?
That may be because there aren't any rows that meet the criteria. We could correct that with:

Excel Formula:
=LET(
ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))),
ut, UNIQUE(ft),
tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))),
t_c, HSTACK(ut, tcount),
IFERROR(FILTER(t_c, tcount=MAX(tcount)), "")
)


Or maybe some dates are stored as text. The same for dates in W7 and Y7.

As Fluff said, a sample of your data would be helpful.
 
Upvote 0
Thanks both - I cannot use XL2BB (at work and blocked) and data is huge and I feel would only overcomplicate things (partly why I use named ranges vs column BDE etc).

The above works exactly right, thanks, I'm just after a tweak to move or remove the count volume, then its spot on - I did get an error at first - user error - I pointed to dates that weren't in data - when I updated the dates that were there, it tells me the most occurring theme and its count)

I guess therefore my questions are:

How can I remove the count all together so that just the theme is returned? the count is a nice extra but not needed, I simply need the theme to be shown.

as a nice to have, How do I amend the first formula so that instead of the result offering the theme and then its count horizontally (F2:G2 in above) that it does it vertically (F2:F3 - number under theme)?

There are hundreds of thousands of rows over hundreds of columns - getting a tied result is unlikely if that is perhaps an issue with turning the horizontal to vertical and I could easily live with the risk of a tie breaking it.

Many thanks,
 
Upvote 0
Try this:

For just the themes:

Excel Formula:
=LET(
ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))),
ut, UNIQUE(ft),
tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))),
IFERROR(FILTER(ut, tcount=MAX(tcount)), "")
)

For the list transposed:

Excel Formula:
=LET(
ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))),
ut, UNIQUE(ft),
tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))),
t_c, HSTACK(ut, tcount),
IFERROR(TRANSPOSE(FILTER(t_c, tcount=MAX(tcount))), "")
)

Let me know if that works.
 
Upvote 1
Solution
If I understand your request re: vertical arrangement correctly, you would just need to wrap the whole formula in a transpose():
Excel Formula:
=TRANSPOSE(LET(
ft, FILTER(Theme,(ReceivedDate>=W7)*(ReceivedDate<Y7)*ISNUMBER(SEARCH("Tin", Product))),
ut, UNIQUE(ft),
tcount, BYROW(ut, LAMBDA(x, SUM((ft=x)*1))),
t_c, HSTACK(ut, tcount),
FILTER(t_c, tcount=MAX(tcount))
))
1723220885643.png
 
Upvote 0
Both of those work spot on felixstraube - many thanks, exactly what was needed - I don't get how it works, but it does and I really appreciate your time in helping, thank you.

Asebestos_Jen, that also worked a treat to 'rotate' the theme and volume - many thanks, I hadn't even considered that or the fact that the answer need not be that complicated etc

Thank you everyone - my spreadsheet works as I want it to - least for now!
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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