Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

If then formula fails to return value but indicates no error

Posted on 2016-09-08
6
Medium Priority
?
92 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 2000 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 
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

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…
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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