View Full Version : Calculate days and catagorize in report


mkelly
12-31-2004, 07:31 AM
I have a database the logs [start date] and then [test date]. I want to run a query for a report that will calculate how many days between [start date] and [test date] and then report it in 4 catagories on a report.

for example
if it is greater than 1 but less than 30 I want it to be catagory 1
if it is equal to 30 but less than 60 I want it to be catagory 2
if it is equal to 60 but less than 90 I want it to be catagory 3
if it is equal to 90 (or [test date] is null) I want it to be catagory 4

Any help greatly appriciated.

Thanks

FLabrecque
12-31-2004, 07:58 AM
Have you looked at the function DateDiff? It would be a great start. Also, try searching the forum. You should find a couple of nice answers to this.

mkelly
12-31-2004, 08:20 AM
thanks, I know how to figure the days what I am having trouble with is getting it to report a disserent catagory on the report based on the amount of days.

spowers21
12-31-2004, 09:40 AM
Create a field in your querie with a nested IIF statement. Example: Category:IIF([StartDate]-[Testdate] between 1 and 29,1,IIF([StartDate]-[TestDate] between 30 and 59,2,IIF([StartDate]-[Testdate] between 60 and 89,3,IIF([StartDate]-[Testdate]=90,4,IIF([StartDate]-[TestDate] Is Null,4)))))

mkelly
01-01-2005, 08:15 AM
Thanks for the help!

Mile-O
01-01-2005, 10:05 AM
Create a function with a SELECT CASE structure - it's faster than all those immediate ifs in one expression.

Pat Hartman
01-01-2005, 12:33 PM
If you have a newer version of Access, you can also look at the Partition() function. But the easiest of all is to let the report's sorting and grouping options group the data for you. That won't require any coding.