Avatar of Tim Ragan
Tim Ragan
Flag for United States of America asked on

If then formula fails to return value but indicates no error

I'm writing a time card report to list attendance transactions for an employee based on a date range.  Some transactions will entered for a vacation day, sick, day, or holiday.  The field in the record could also be populated with other identifiers unrelated to vacation, holiday, or sick pay.  I need to identify the hours included that are paid but not actually worked because they cannot be used calculate overtime pay.  My formula: IF {SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID} like ["VACATION", "SICK", "HOLIDAY"] THEN 0 else {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED}.   SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID is the column containing VACATION, SICK, HOLIDAY.  My intent is return the hours worked if the record IS NOT VACATION, SICK, HOLIDAY else I would return zero.  This would allow me to sum the total hours actually worked.  It returns the zero when VACATION, SICK, HOLIDAY but all other records return no value.  With my sample data they should return 8 (hours).

This report was written using version 8.5
Crystal Reports

Avatar of undefined
Last Comment
James0628

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
James0628

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Tim Ragan

ASKER
Thank you James.  I reworked the order of the formula and have it working.   Lucky you to not need to work in Crystal 8.5.   I have a specific need to work in the very old version of the product or I'd be using the latest.
Tim Ragan

ASKER
I added my thanks in a comment to the question but here it is again.  Thank you James.  Problem resolved.
James0628

Was the problem nulls, or something else?  Just curious.

 James
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Tim Ragan

ASKER
The data includes records with nulls.  The null rows need to be part of my result so, as you suggest, I'm evaluating the null records in the first.  This is my new formula:  IF  isnull({SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}) then {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED} else if {SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}
in ["VAC", "HOL","SIC","BER","JURY"] then 0 else if not ({SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID} like ["VAC", "HOL","SIC","BER","JURY"]) then {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED}

My result is a list of records showing hours actually worked and zero hours where the time was vacation, sick, PTO, etc.

Thanks again for the direction.
James0628

Ah.  I was excluding the hours in the null records.  If you want to include them, you should be able to use

IF not isnull({SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}) and
 {SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID} in ["VAC", "HOL","SIC","BER","JURY"] then 0
else {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED}

Open in new window


 The results should be the same as with your formula.  This one is just simpler.

 If nothing else, you really don't need the last If in the formula that you posted.  You could shorten your formula to

IF  isnull({SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}) then {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED} else if {SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}
in ["VAC", "HOL","SIC","BER","JURY"] then 0 else {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED}

Open in new window


 James