If formula

kumar0318

New Member
Joined
Mar 25, 2022
Messages
11
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Hello- I have a date column in column A, and I need to build an "IF" formula based on the following conditions:

0- days if its future date
1- If its less than 30 days
2 - if its less than 60 days
3- If its less than 120 days
4- if its more than 120 days
 
OK, try this formula for a value in cell A1:
Excel Formula:
=IF(TODAY()-A1>120,4,IF(TODAY()-A1>60,3,IF(TODAY()-A1>30,2,IF(TODAY()-A1>0,1,0))))
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Alternatively, you can try this:
Excel Formula:
=MIN(4,MAX(0,CEILING((TODAY()-A1)/30,1)))
 
Upvote 0
Alternatively, you can try this:
Excel Formula:
=MIN(4,MAX(0,CEILING((TODAY()-A1)/30,1)))
Oops, I just noticed that it's not a perfect gap of 30 days. Hence, this formula won't work.

The below formula might work instead.
Excel Formula:
=LOOKUP(TODAY()-A1,{0,30,60,120,9999},{0,1,2,3,4})
 
Upvote 0
Oops, I just noticed that it's not a perfect gap of 30 days. Hence, this formula won't work.

The below formula might work instead.
Excel Formula:
=LOOKUP(TODAY()-A1,{0,30,60,120,9999},{0,1,2,3,4})
Your formula is off by one "shift", but it can be fixed (I think you missed the part about future dates).

My formula also might require one minor edit. If the current date should return "1" and not "0", then:
Rich (BB code):
=IF(TODAY()-A1>120,4,IF(TODAY()-A1>60,3,IF(TODAY()-A1>30,2,IF(TODAY()-A1>0,1,0))))
would need a minor change like this:
=IF(TODAY()-A1>120,4,IF(TODAY()-A1>60,3,IF(TODAY()-A1>30,2,IF(TODAY()-A1>=0,1,0))))

In order to get your formula to match up with the rules in post #1, it should look like this:
Rich (BB code):
=LOOKUP(TODAY()-A1,{-9999,0,30,60,120},{0,1,2,3,4})

Here is a grid with a bunch of dates, and shows what it should return and what the various formulas return.
1678922565904.png
 
Upvote 0

Forum statistics

Threads
1,215,654
Messages
6,126,048
Members
449,282
Latest member
Glatortue

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top