问题
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