Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: IF Then formula problem Post Reply Post New Topic
Author Message
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Topic: IF Then formula problem
     Posted: 16 Oct 2009 at 11:34am
I'm trying to create a formula that calculates a dollar amount based on a key field.  The key fields have different values.  Some are zero, some are 160, some are 250.  And I have about 50 key fields to calculate.

I had no trouble creating the first If Then formula..

If {SERVICE_TYPES.SE_KEY} = 2 Then
    {WORK.WO_WORK_HOURS} * 0
Else
    {WORK.WO_WORK_HOURS} * 0

I'm not sure how to continue from here.  I have 3-57 still to use.  I work for a service company and we are trying to create a report that calculates a dollar amount for hours worked based on our normal hourly rates.  We also have contracts and warranty rates that will be at zero.  In the example above that "2" would represent a warranty job.

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Oct 2009 at 11:59am
Can you post some sample data and en explanation of how you want it calculated?
IP IP Logged
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Posted: 16 Oct 2009 at 12:19pm
Sure,

I have a piece of hardware that we have done service on for 1 year.  Let's say there are 10 jobs on it.  We have different service levels depending on the equipment, some cost more for service than others but it is only 2 tiered pricing....$160 per hour or $250 per hour. 

So, let's say that of these 10 jobs 6 of them were done under the warranty...and this is what we call our Premium equipment service level.  So the other 4 jobs would be billed at $250 dollars an hour.

In our database the service types table looks like this:

SE_KEY  SE_DESC
2             Standard Contract Service
3             Standard Hourly Time and Material
4             Premium Contract Service
5             Premium Hourly Time and Material


So, I'm trying to use the SE_KEY data to string together a series of IF Then statements to calculate the correct charge for each job.


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Oct 2009 at 1:22pm
I think I understand although I am still guessing a bit here.
I think based on the SE field you just want to have a value amount of 0, 160 or 250. Then You can use this formula in another formula that would be your total for that job. That formula can then be Summed at any group level for the total of a job.
Your 'Amount' formula would be
if {SERVICE_TYPES.SE_KEY} in [2,4] then 0 else
if {SERVICE_TYPES.SE_KEY} = 3 then 160 else
if {SERVICE_TYPES.SE_KEY} = 5 Then 250 else -10000
 
I threw the else -10000 on as a way to find things that slip through the other values. It can be removed as it is just a way to look for formula errors.
you can use this formula field as your dollar base in another formula to multiply by the hours for that job.
Is this what you are looking for?


Edited by DBlank - 19 Oct 2009 at 8:54am
IP IP Logged
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Posted: 19 Oct 2009 at 8:48am
Yes, this looks like what I need.  Can I put more values in the brackets:

if {SERVICE_TYPES.SE_KEY} in [2,4,6,18] then 0 else

Like that?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Oct 2009 at 8:52am
Yep, as many as you need just like that seperated via the comma.  


Edited by DBlank - 19 Oct 2009 at 8:53am
IP IP Logged
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Posted: 19 Oct 2009 at 12:03pm
Ah, one more thing with this.  This standard or premium service charge needs to be multiplied by the hours actually worked on the job.  They are contained in {WORK.WO_WORK_HOURS} .

So would it be:
if {SERVICE_TYPES.SE_KEY} = 3 then {WORK.WO_WORK_HOURS} *160 else



IP IP Logged
Eldab
Newbie
Newbie


Joined: 16 Oct 2009
Online Status: Offline
Posts: 10
Quote Eldab Replybullet Posted: 19 Oct 2009 at 12:09pm
Never mind just tested that and it worked.  Thank you so much for your help with this.  :)
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum