on 03-20-2021 2:02 AM
I have a report in Crystal report that has a promise date and a shipped day, both data types are number. The data is stored as yyyymmdd in the database (DB2) so I created two formula fields to change the date format to display mm/dd/yyyy. I have two parameter "StartDate and EndDate" and the type is string. I need to find the difference between these two fields and display the date difference on the report.
Here is the formula fields I have created:Date(0000,00,00) is what's causing the issue - there is no such date. I would put this date either far in the future or far in the past. Then add an "If" statement around the date diff that will return 0 or null if the dates are the "dummy" date that you use. Also, here's what I'd do for the formulas:
{@Promise_Dt}
If {Command.PROMISE_DT} = 0 then
date(1970,01,01)
else
Date (Truncate({Command.PROMISE_DT}/10000),Truncate(Remainder({Command.PROMISE_DT},10000)/100),Remainder({Command.PROMISE_DT},100))
{@Shipped_Day}
If {Command.SHIP_DT} = 0 then
date(1970,01,01)
else
Date (Truncate({Command.SHIP_DT}/10000),Truncate(Remainder({Command.SHIP_DT},10000)/100),Remainder({Command.SHIP_DT},100))
{@DateDifference}
if {@Promise_dt} > date(1970,01,01) and {@Shipped_day} > date(1970,01,01) then
DateDiff("d",{@Shipped_day},{@Promise_dt})
//below is optional
else 0
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks dell.stinnett-christy that resolved the issue I was having. Now I am trying to create two more formula fields: OnTime and Late using the date from the DateDiffence formula.
OnTime formula:
if {@dateDiff} > 0 then Count ({@dateDiff})
I get 0.00 for this formula ( I am trying to get all numbers that are greater than 0)
Late formula:
if {@dateDiff} < 0 then Count ({@dateDiff})
For this formula I get all the records ( I am trying to get all number lower than zero)
Unfortunately, you can't use Count() like that. You have two options:
1. If you need to show the count at the end of the report, use a Running Total. This is the easiest way to do this and it looks something like this:
Field to Summarize: {@dateDiff}
Evaluate: Use a formula
{@dateDiff} > 0
Reset: Never
2. If you need to show the count at the top of the report, you'll need to use a formula that will identify the records to count. Something like this:
If {@dateDiff} > 0 then 1 else 0
Then you would use Sum() instead of Count() to get the count you're looking for.
-Dell
The formula I provided returns a 1 if the difference > 0 and 0 if it's less than or equal to 0. If you want to count the records that have non-0 differences - either greater than 0 or less than 0 - you'll have to make a minor change to the formula - like this:
{@NotZero}
If abs({@dateDiff}) > 0 then 1 else 0
Then, you'll use a Sum of {@NotZero} to count the non-0 records. To do this, click on the "Summary" button in the button bar (looks like a capital E) or go to the Insert >> Summary menu option, select {@NotZero) as the field to summarize, select Sum as the aggregation, set it to be a grand total, and click on OK. The summary will appear in bold in the report footer section. Move it to where you need it.
-Dell
Thanks again Dell Stinnett-Christy I was able to get both formulas to work, you are the BEST!!!!
I'm not sure if I did it correct. Do I just acept the best answer?
try to change:
"date(0000,00,00)"
to
"date(1900,01,01)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.