Maximum Value Based on a Condition

别来无恙 提交于 2021-02-05 08:29:51

问题


I have a mock dataset in Excel that I want to print the most recent date, but I want it to be the latest date such that the Type is "referral":

Type      Date
referral  1/6/2017
classroom 1/7/2017
referral  1/8/2017
classroom 1/9/2017

What would that function look like?


回答1:


You can use an array formula like this (assuming your columns are A and B):

=MAX(IF(A2:A5="referral",B2:B5))

and enter it by pressing Ctrl + Shift + Enter (CTRL+SHIFT+ENTER).

When entered by Ctrl + Shift + Enter, Excel will put curly brackets around it like this:

{=MAX(IF(A2:A5="referral",B2:B5))}

Note that you cannot type the brackets "{ }" yourself.

Also, as Scott Craner points out, you should limit the ranges in an array formula so as to prevent iterating through an entire column (e.g., I've edited to have A2:A5 instead of A:A).

Here it is in action:




回答2:


Use this formula:

=AGGREGATE(14,6,B2:B5/(A2:A5="referral"),1)

If you have Office 365 Excel then use this formula which is not an array type:

=MAXIFS(B:B,A:A,"referral")



来源:https://stackoverflow.com/questions/41898006/maximum-value-based-on-a-condition

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