Solved

If then formula fails to return value but indicates no error

Posted on 2016-09-08
6
37 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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