Solved

If then formula fails to return value but indicates no error

Posted on 2016-09-08
6
52 Views
Last Modified: 2016-09-09
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
0
Comment
Question by:Tim Ragan
  • 3
  • 3
6 Comments
 
LVL 34

Accepted Solution

by:
James0628 earned 500 total points
ID: 41791073
Could the field be null?  If so, that may be the problem.  If CR encounters a null when evaluating a formula, it just stops evaluating the formula at that point, and the formula doesn't produce a value (it's null).

 I haven't really used CR 8.5, but in later versions you can use the IsNull function to test for nulls.  When checking a field for nulls, you need to do that before you do anything else with that field.  So, your formula would be

IF IsNull ({SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID}) or
 {SHOPFLOOR_EMPLOYEE_TIME.IN_REASON_CODE_ID} like ["VACATION", "SICK", "HOLIDAY"] THEN
  0
else
  {SHOPFLOOR_EMPLOYEE_TIME.HOURS_WORKED}

Open in new window


 Like I said, I haven't used 8.5, so I don't know if it has the IsNull function, but you could try that and see if it works.  If HOURS_WORKED could be null, you should probably check that too.

 James
0
 

Author Comment

by:Tim Ragan
ID: 41791238
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.
0
 

Author Closing Comment

by:Tim Ragan
ID: 41791240
I added my thanks in a comment to the question but here it is again.  Thank you James.  Problem resolved.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 34

Expert Comment

by:James0628
ID: 41791586
Was the problem nulls, or something else?  Just curious.

 James
0
 

Author Comment

by:Tim Ragan
ID: 41791611
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.
0
 
LVL 34

Expert Comment

by:James0628
ID: 41791761
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
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now