Solved

If then formula fails to return value but indicates no error

Posted on 2016-09-08
6
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 35

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
Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

 
LVL 35

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 35

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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