grath
grath

Reputation: 66

Excel formula returning false on certain cells

I have a nested IF statement in excel in several columns that is returning FALSE on certain cells.

=IF(DATEDIF(B2,C2,"y")<5,3.077,IF(AND(DATEDIF(B2,C2,"y")>5,DATEDIF(B2,C2,"y")<10),3.5385,IF(AND(DATEDIF(B2,C2,"y")>10,DATEDIF(B2,C2,"y")<15),3.846,IF(AND(DATEDIF(B2,C2,"y")>15,DATEDIF(B2,C2,"y")<20),4.308,IF(AND(DATEDIF(B2,C2,"y")>20),4.615)))))

These work:

B2 - 2/3/95, C2 - =Today()

B2 - 2/21/08, C2 - =Today()

B2 - 9/1/99, C2 - =Today()

These don't:

B2 - 2/6/12, C2 - Today()

B2 - 3/1/07, C2 - Today()

B2 - 12/8/11, C2 - Today()

B2 - 3/31/97, C2 - Today()

Any help would be greatly appreciated.

Upvotes: 0

Views: 55

Answers (1)

user4039065
user4039065

Reputation:

Your problem is that you have created a 'pocket' where the difference in years in neither less than 5 or greater than 5; in other words, 5. You could fix this by adding an equal sign to one of them; e.g. <= 5 or >=5.

However, you might also wish to use the logic of an IF statement and reduce your formula substantially. Once you test for less than 5 you know that anything that continues in the FALSE processing portion of that IF is going to be 5 or greater. You do not have to test for that.

=IF(DATEDIF(B2,C2,"y")<5, 3.077,
 IF(DATEDIF(B2,C2,"y")<10, 3.5385,
 IF(DATEDIF(B2,C2,"y")<15, 3.846,
 IF(DATEDIF(B2,C2,"y")<20, 4.308,
  4.615))))

This can also be written as a LOOKUP function.

=LOOKUP(DATEDIF(B2,C2,"y"), {0,5,10,15,20}, {3.077,3.5385,3.846,4.308,4.615})

Upvotes: 2

Related Questions