Return the most frequently-appearing corresponding value based on given criterion

megera716

Board Regular
Joined
Jan 3, 2013
Messages
142
Office Version
  1. 365
Platform
  1. Windows
I have dates in Column A, person's name in B, locations in C. Each date, a name is assigned to a location, but that is not my circus 😁😌

At the end of the month, I need to find out which location each name was assigned to the most.

The data is basically exactly like this but with 100+ potential names and 30 potential locations.
1721770698913.png


What I would like is something off to the side that just tells me which value was the most frequently occurring for each name. If it's a tie between locations, it's okay if it returns an error (or maybe it says "Manual") and then the person who does own this circus can use their judgment to decide.
1721770840100.png
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try:

Book1
ABCDEF
1DateNameLocationNameMost Frequent Location
210-JulName 1ZName 1Z
310-JulName 2YName 2Y
410-JulName 3XName 3X
511-JulName 1Y
611-JulName 2X
711-JulName 3X
812-JulName 1Z
912-JulName 2Y
1012-JulName 3X
1113-JulName 1X
1213-JulName 2Y
1313-JulName 3Z
Sheet10
Cell Formulas
RangeFormula
F2:F4F2=INDEX($C$2:$C$13,MODE(IF($B$2:$B$13=E2,{1,1}*MATCH($C$2:$C$13,$C$2:$C$13,0))))
 
Upvote 1
Solution
What if two or more locations are equally frequent? wanna show them all? how? in one cell concatenated, in different cells?
 
Upvote 0
Taking that into account, how about?:

Location are randomly generated for testing (press F9 to update), and columns G:I are just for control.

Freq.xlsx
ABCDEFGHI
1DateNameLocationNameMost frequent locationXYZ
210/07/2024Name1XName1Y154
310/07/2024Name2ZName2Y253
410/07/2024Name3XName3X, Z424
511/07/2024Name1Z
611/07/2024Name2Y
711/07/2024Name3X
812/07/2024Name1Y
912/07/2024Name2Y
1012/07/2024Name3X
1113/07/2024Name1Z
1213/07/2024Name2Y
1313/07/2024Name3Z
1414/07/2024Name1Y
1514/07/2024Name2Z
1614/07/2024Name3Z
1715/07/2024Name1Z
1815/07/2024Name2X
1915/07/2024Name3Z
2016/07/2024Name1Y
2116/07/2024Name2X
2216/07/2024Name3Y
2317/07/2024Name1Y
2417/07/2024Name2Y
2517/07/2024Name3Y
2618/07/2024Name1Z
2718/07/2024Name2Y
2818/07/2024Name3X
2919/07/2024Name1Y
3019/07/2024Name2Z
3119/07/2024Name3Z
Sheet2
Cell Formulas
RangeFormula
C2:C31C2=CHAR(RANDARRAY(30,1,88,90, TRUE))
F2:F4F2=LET(d, $B$2:$C$31, n, CHOOSECOLS(d, 1), l,CHOOSECOLS(d, 2), fl, FILTER(l,n=E2), f, MATCH(fl, fl,0), fr, DROP(FREQUENCY(f, f), -1), i, FILTER(f, fr=MAX(fr)), TEXTJOIN(", ", ,INDEX(fl, i)) )
G2:I4G2=SUM(($B$2:$B$31=$E2)*($C$2:$C$31=G$1))
A14:A31A14=A11+1
Dynamic array formulas.
 
Last edited:
Upvote 0
Try:

Book1
ABCDEF
1DateNameLocationNameMost Frequent Location
210-JulName 1ZName 1Z
310-JulName 2YName 2Y
410-JulName 3XName 3X
511-JulName 1Y
611-JulName 2X
711-JulName 3X
812-JulName 1Z
912-JulName 2Y
1012-JulName 3X
1113-JulName 1X
1213-JulName 2Y
1313-JulName 3Z
Sheet10
Cell Formulas
RangeFormula
F2:F4F2=INDEX($C$2:$C$13,MODE(IF($B$2:$B$13=E2,{1,1}*MATCH($C$2:$C$13,$C$2:$C$13,0))))

@Eric W , this worked perfectly, thank you!

Would you mind explaining how it works? I understand INDEX of range C and if B contains the value in E and what MODE does, but the 1s in curly brackets and why the MATCH is also referencing column C has me all 😵 (when I use INDEX/MATCH, the column I am INDEXing isn't part of the MATCH criteria!)
 
Upvote 0
Sure -

=INDEX($C$2:$C$13,MODE(IF($B$2:$B$13=E2,{1,1}*MATCH($C$2:$C$13,$C$2:$C$13,0))))

The part in red checks for your criteria. If it finds a row that matches, it goes to the MATCH part. The MATCH returns the index of the first match it finds. So if you compare the list against itself (C2:C13 against C2:C13) and the list is {A,B,A,B,A}, it returns {1,2,1,2,1}, since when it looks at the second and third As, they both find the first A. So the return list shows the first location of each individual item. Then MODE returns the most common number, 1 in this example. Then finally the INDEX uses that number to look into the range and return the actual value.

The {1,1} part is to avoid an error that MODE can cause. If there's only one matching value, so that the result list looks like {3}, then MODE will cause an error because there's only 1 number. Multiplying {3} by {1,1} results in {3,3}, and MODE will return 3. If there are more results, multiplying by {1,1} doesn't hurt since each result is repeated by the same amount.

Felix raises a good question, is it possible that there will be more than 1 most common value? He offers one solution, here's a way to update my formula to include multiple modes using MODE.MULT:

Book1
ABCDEFG
1DateNameLocationNameMost Frequent Location
210-JulName 1ZName 1ZY
310-JulName 2YName 2Y
410-JulName 3XName 3X
511-JulName 1Y
611-JulName 2X
711-JulName 3X
812-JulName 1Z
912-JulName 2Y
1012-JulName 3X
1113-JulName 1Y
1213-JulName 2Y
1313-JulName 3Z
14
Sheet10
Cell Formulas
RangeFormula
F2:G2,F3:F4F2=INDEX($C$2:$C$13,TRANSPOSE(MODE.MULT(IF($B$2:$B$13=E2,{1,1}*MATCH($C$2:$C$13,$C$2:$C$13,0)))))
Dynamic array formulas.


Multiple modes will just spill to the right, or we can use TEXTJOIN to put them in a single cell. Hope this helps!
 
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