Excel/Max If Formula

Advertisement


Question
QUESTION: Hi Tom,
I am stumped on a complex Max If formula. I have data in column CX. I have two dates relating to that data in columns DB and DC (start date, end date). I'd like to use a single formula that looks at both dates and if the weeknum & year of both dates are equal to the current weeknum & year, take the max value of those qualified numbers in row CX. Any guidance is greatly appreciated!

Jesse

ANSWER: Jesse
Data in CX

Start Date in DB
End  Date in DC

this is probably what you were looking for -
=MAX(--(WEEKNUM($DB$1:$DB$50)=WEEKNUM(TODAY())),--(YEAR($DB1:$DB$50)=YEAR(TODAY())),--(WEEKNUM($DC$1:$DC$50)=WEEKNUM(TODAY())),--(YEAR($DC1:$DC$50)=YEAR(TODAY())),$CX$1:$CX$50)

entered with Ctrl+Shift+Enter.  But that doesn't work because weeknum does not appear to work with mulitple cells as an argument.  Instead, I put in   =weeknum(DB1) in DD1 and =weeknum(DC1) in DE1 and drag filled those formulas down. Then I used the below formula


=MAX(--($DD$1:$DD$50=WEEKNUM(TODAY())),--(YEAR($DB1:$DB$50)=YEAR(TODAY())),--($DE$1:$DE$50=WEEKNUM(TODAY())),--(YEAR($DC1:$DC$50)=YEAR(TODAY())),$CX$1:$CX$50)

entered with Ctrl+Shift+Enter and that worked for me.  I am afraid you will have to use added columns otherwise you will have to calculate the end dates for your the current weeknum and put those in your formula instead of trying to use weeknum

--
Regards,
Tom Ogilvy


---------- FOLLOW-UP ----------

QUESTION: I had to rearrange your formula to fit the exact data I'm working with but I'm not getting the correct result. I'm not sure if the data I plugged in compromised the formula...Is there something wrong with my formula:

Named Range of Data to find Max value: WinStreak
Named Range of Dates to match: WinStreakStartDate, WinStreakEndDate
Named Range to refer to today's date in code: Today ie:(DAY(TODAY() & MONTH(TODAY() & YEAR(TODAY())

Formula to find max value in 'WinStreak' if the two dates equal the the value of 'Today'

=MAX(--((DAY(WinStreakEndDate)&MONTH(WinStreakEndDate)&YEAR(WinStreakEndDate))=Today),--((DAY(WinStreakStartDate)&MONTH(WinStreakStartDate)&YEAR(WinStreakStartDate))=Today),WinStreak)

Answer

If you have dates in the columns WinStreakStartDate, WinStreakEndDate

So the criteria would be that today is greater than or equal to the startdate in that row and less than or equal to the enddate for that row - then consider the value in winstreak for that row.  The formua for that would be:

=Max((WinStreakStartDate<=Today)*(WinStreakEndDate>=Today)*WinStreak)

Entered with Ctrl+Shift+enter


assume the named range Today is a single cell.  

also, my original formula appears screwed up and not sure why - I may have copied the wrong formula.  

=MAX(--($DD$1:$DD$50=WEEKNUM(TODAY())),--(YEAR($DB1:$DB$50)=YEAR(TODAY())),--($DE$1:$DE$50=WEEKNUM(TODAY())),--(YEAR($DC1:$DC$50)=YEAR(TODAY())),$CX$1:$CX$50)

should have been

=MAX(($DD$1:$DD$50=WEEKNUM(TODAY()))*(YEAR($DB1:$DB$50)=YEAR(TODAY()))*($DE$1:$DE$50=WEEKNUM(TODAY()))*(YEAR($DC1:$DC$50)=YEAR(TODAY()))*$CX$1:$CX$50)
entered with Ctrl+Shift+enter.  Anyway, you are not using that formula, but just for completeness.


--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.