Search code examples
crystal-reportsdatediff

Crystal Reports 2011: Calculate the number of times a value occures and the number of days in between


It occurs to me that I might have been able to find the answer to this but so far i've come up short. Also, I am pretty new to Crystal Reports (2011) so please forgive my ignorance if this is something I've missed. Here's the issue:

I have a report where I am pulling the number of times a value happens for a specific target, specifically how many times a specific procedure happens for a person within a specified date range. I have the results grouped by person.

I show the person, the procedure code and the date the procedure happend within that group.

What I NEED to do now, is to figure out how to return some type of visual indicator that there is at least 3 days in between each procedure for each person.. example..

[GROUP #1 NAME]....................[PROC_CODE]......[PROC_DATE]

[{Last_Name}, {First_Name}].....PROCEDURE..........PROCEDURE DATE

(Please forgive the "....." as I was trying to space out the headers and results)

Having said all that, the "Procedure Date" I would like to show up in RED if the next result within the group (by person) falls within 3 or less days from the last date. I am really hoping this makes sense to someone. Thank you in advance for your help!


Solution

  • create a formula called "DateDiff": DateDiff("d", {Proc_Date}, previous({Proc_Date}))

    then in your Section Expert, choose the group that your data is in. Click the color tab. Choose the "x-2" formula button and enter: if {@DateDiff} > 3 then crred else crnocolor

    edit so your next group doesnt pick up the last value:

    if ({group1_field} = previous({group1_field})) then
     if {@DateDiff} > 3 then crred else crnocolor
    else
    crnocolor