Finding Mode based of conditional criteria

冷暖自知 提交于 2019-12-11 15:28:24

问题


I would like to be able to find the most common value given a certain criteria in an adjacent column. For example:

>**ROW A**  -----   **ROW B**  
>Blue ---------- Jason  
>Blue ---------- Jason  
>Blue ---------- Charles   
>Red ---------- Alfred  
>Red ---------- Alfred  
>Red ---------- Barry  
>Green --------- Barry

I would like a formula that could look like the following

if(X=Row_A_Value,Mode of X)

For instance if "BLUE" then the output would be "JASON". If "RED" the output would be "ALFRED"

I've tried using Index(Mode(Match)) without any luck...

Thanks for your help!


回答1:


Not exactly the prettiest formula, but this array formula works: (line break added for readability)

= INDEX(B1:B7,MATCH(MAX(COUNTIFS(A1:A7,"Blue",B1:B7,B1:B7)),
  COUNTIFS(A1:A7,"Blue",B1:B7,B1:B7),0))

There probably is a more efficient way but this is just the first one I could think of.

Obviously, just replace the two instances of "Blue" in the formula above with "Red" in order to search for red instead.

Note this is an array formula, so you must press Ctrl+Shift+Enter after typing this formula rather than just Enter.

See below, working example.



来源:https://stackoverflow.com/questions/48629972/finding-mode-based-of-conditional-criteria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!