?
Solved

Excel formula to get the Max of a number from a range, where the max is below a specific number

Posted on 2013-01-11
6
Medium Priority
?
270 Views
Last Modified: 2013-01-22
In the example attached, how can I adjust the formula so that it picks the max of the LookupDate that is before today's date?

Assuming today is 1/10/2013

ie, pick the red ResultDate instead of the yellow

=INDEX(Table92[ResultDate],MATCH(MAX(IF(Table92[code]=$G9,Table92[LookupDate],0)),Table92[LookupDate],0))

Open in new window


Thank You
example.xlsx
0
Comment
Question by:newparadigmz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 800 total points
ID: 38768093
Try:

=INDEX(Table92[ResultDate],MATCH(MAX(IF((Table92[code]=$G9)*(Table92[LookupDate]<TODAY()),Table92[LookupDate],0)),Table92[LookupDate],0))

Open in new window


Array-entered, of course :)
0
 
LVL 7

Accepted Solution

by:
leptonka earned 800 total points
ID: 38768237
What about this:

=MAX(IF((Table92[code]=G6)*(Table92[LookupDate]<TODAY()),Table92[ResultDate],0))

Open in new window

ctrl+shift+enter, too.

Cheers,
Kris
0
 

Author Comment

by:newparadigmz
ID: 38768556
does this line work the way sumproduct works, by generating an array of boolean 0's and 1's and multiplying that by the data?

IF((Table92[code]=G6)*(Table92[LookupDate]<TODAY())

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:leptonka
ID: 38768589
It is two boolean expression multiplied - in this case multiplication is the same as AND logical operation, it means that both of the two conditions must be true. If both are true, we use the ResultDate, if not, we use 0. So the result is an array where you have dates only if the LookupDate is before today AND the code is the code you are looking for. All the other data is 0. So using max you have the maximum of these dates.
You can leave out IF and use this format which is similar to sumprodact:
=MAX((Table92[code]=G7)*(Table92[LookupDate]<TODAY())*Table92[ResultDate])

Open in new window

Because if one of the conditions is not true, the multiplication gives 0. If the conditions are true, the booleans = 1, so you can multiply with the ResultDate. The array is exactly the same as above.

Cheers,
Kris
0
 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 400 total points
ID: 38768771
I don't think you can simply compare the LookupDate column directly to TODAY() because your LookupDates aren't true dates, they are just numbers, so the comparison Table92[LookupDate]<TODAY() always returns FALSE - try converting today's date to a similar format within the formula, i.e. with TEXT function like this

=TEXT(TODAY(),"yyyymmdd")+0

So that makes the revised formula

=INDEX(Table92[ResultDate],MATCH(MAX(IF((Table92[ code ]=$G6)*(Table92[LookupDate]<TEXT(TODAY(),"yyyymmdd")+0),Table92[LookupDate],0)),Table92[LookupDate],0))

Edit - in that formula I needed to change the bolded part to [ code ] because otherwise it was being interpreted as a "code tag" - you may need to remove spaces - the correct version is in the attached file

see attached

Note that both your original formula and this revised version rely on no duplicates in that column (which seems to be the case) - if that isn't the case then formulas may fail

regards, barry
barry-example.xlsx
0
 

Author Closing Comment

by:newparadigmz
ID: 38808417
Thanks!

The 'If' seemed to be necessary, although I do not know why.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question