AccesS Formula help

bwlytkr

Board Regular
Joined
Jun 8, 2012
Messages
173
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I could use some help with how to write this formula in ACCESS to determine age bucket for the column DaysAged. It works fine when I input just the formula for <= 30 days but, when I add 30-60, 60-240, and > 240 it isn't calculating correctly. I'm just not sure how to show the days between 30- 60 and 61 -240 ranges. Any help would be appreciated. Here is the formula I was trying to use.

NTG AGE BUCKET: IIF([DaysAged]<=30,"<30 Days",IIF([DaysAged]>30<=60,"31-60 Days",IIF([DaysAged]>60,<=240,"61-240 Days",IIF([DaysAged]>240,">240 Days"))))
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
If you have multiple conditions you have to separate with 'And' or 'Or' --

[DaysAged]>30 And [DaysAged] <=60, so it would like something like this --

IIF([DaysAged]<=30,"<30 Days",IIF([DaysAged]>30 And [DaysAged] <=60,"31-60 Days",IIF([DaysAged]>60 And [DaysAged] <=240,"61-240 Days",IIF([DaysAged]>240,">240 Days"))))
 
Upvote 0
Is the last IIF actually needed?

If you have multiple conditions you have to separate with 'And' or 'Or' --

[DaysAged]>30 And [DaysAged] <=60, so it would like something like this --

IIF([DaysAged]<=30,"<30 Days",IIF([DaysAged]>30 And [DaysAged] <=60,"31-60 Days",IIF([DaysAged]>60 And [DaysAged] <=240,"61-240 Days",IIF([DaysAged]>240,">240 Days"))))
 
Upvote 0
I find the switch function is a clearer and neater option for things like this. If DaysAged returns and integer then:

Code:
Switch([DaysAged]<31,"<30 Days",[DaysAged]<61,"31-60 Days",[DaysAged]<241,"61-240 Days",[COLOR=#ff0000]True[/COLOR],">240 Days")

Note the final True as an argument, this is the equivalent of an Else (if none of the other criteria evaluate to true then this one will and therefore needs to be the last one).
 
Upvote 0
in a like vein:
Code:
Switch([DaysAged]<31,"<30 Days",[DaysAged]<61,"31-60 Days",[DaysAged]<241,"61-240 Days",[COLOR="#FF0000"][DaysAged]>=241[/COLOR],">240 Days")
 
Upvote 0

Forum statistics

Threads
1,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

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