Link to home
Start Free TrialLog in
Avatar of morinia
moriniaFlag for United States of America

asked on

Modifying if statement in Excel

Experts,

I have an if statement throughout a spreadsheet which only caculates the value if it is the month is less than the current month.  It worked fine, until I tried to calculate December which is greater than January.  I had not included year in the "if statement".

This is my statement,  
=IF( MONTH(1&"-"&E$7) <  MONTH(TODAY()),SUMIFS(MCLAIMS,MMONTH,MONTH(1&"-"&E$7),MEDIT,$C9),0)

Can someone tell me the best way to modify this statement so it will work all year, including December
Avatar of NBVC
NBVC
Flag of Canada image

What does this part:

MONTH(1&"-"&E$7)

supposed to evaluate too?

what do you have in E7?
Avatar of morinia

ASKER

Sorry,  E7 has "JAN"   G7 = "FEB"   I7 = "MAR"   K7 = "APR"   ........
Bascially it just allows the same formula to be used throughout the columns.  When the formula is copied from one column to the next it works.

The part of the statement that needs adjusting is, I need to add an "OR" to the if

That code was given by an "expert"  a while back.

I am starting to try it myself, I have to test I came up with this so far


=IF(OR( MONTH(1&"-"&E$7) <  MONTH(TODAY(), MONTH(TODAY() - 1 = 0) ),SUMIFS(MCLAIMS,MMONTH,MONTH(1&"-"&E$7),MEDIT,$C9),0)
I suspect it would be easier to compare whole dates rather than just months. Dates can be rounded up to the end of the month using EOMONTH function. I will take another look when back at PC.
SOLUTION
Avatar of NBVC
NBVC
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morinia

ASKER

Experts,

I was able to get it to work with this formula:

=IF(OR( MONTH(1&"-"&E$7) <  MONTH(TODAY()),MONTH(TODAY()=1)),SUMIFS(MCLAIMS,MMONTH,MONTH(1&"-"&E$7),MEDIT,$C9),0)

This will get me through December.   I hope it works in February for January.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of morinia

ASKER

I had to make a slight modification to make it work.