Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Number range formula Post Reply Post New Topic
Author Message
fusion
Groupie
Groupie


Joined: 12 Nov 2007
Location: United States
Online Status: Offline
Posts: 93
Quote fusion Replybullet Topic: Number range formula
     Posted: 05 Dec 2007 at 5:35am
I have two different fileds:
emp # (datatype: Char) and Salary (datatype: number)
Emp no has values 100, 200, 300, 400, .... 1400, 1500
salary has values in Dollar amount.

Based on emp# condition I have to add the salary fileds.

The condition is
If emp#>=400 and emp#<1400, sum(Salary).

I used the if then else condition:
If emp#>='400' and emp#<'1400'
then  sum(Salary)
else 0

After I used this as a formula, I get zero value.
I tried to take out the condition emp#<1400, the formula sums up all the salary (does not care about the condition emp#>=400).

What did I do wrong?

IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 05 Dec 2007 at 6:15am
It could be to do with the sort order for emp#.  You say it is a Char, not a number so it will sort as 100, 1100, 1200,.... 200 etc not 100, 200, 300 ...
 
IP IP Logged
fusion
Groupie
Groupie


Joined: 12 Nov 2007
Location: United States
Online Status: Offline
Posts: 93
Quote fusion Replybullet Posted: 05 Dec 2007 at 6:38am
Thank you for the reply.
that is possible but how would I solve this problem?
sb told me that I could use val (emp#) >=400 which I tried but with no change in result.
The formula sum(salary) is not using the filter val (emp#) >=400

If val (emp#) >= 400 then sum(salary)
else 0


IP IP Logged
fusion
Groupie
Groupie


Joined: 12 Nov 2007
Location: United States
Online Status: Offline
Posts: 93
Quote fusion Replybullet Posted: 05 Dec 2007 at 8:37am
The Problem was with the sum function. I placed the sum(salary) in the report footer section. What I did different his time was, I used the formula:

If val(emp#) >=400 and val(emp#) <9999
then Salary
else 0

What I was using before was
If val(emp#) >=400 and val(emp#) <9999
then sum(Salary)
else 0

After changing the formula I put the formula field in the details section of the report and calculated the summary of that filed in the report footer section.

That solved my problem. I still do not know why I could not use the If then else condition to sum those values where i use the filter for emp#. It must have sth to do with sum function and If then else condition.

IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 07 Dec 2007 at 7:11am
The reason it wasn't working is because the If..Then wasn't taking a conditional sum.  The logic was more like:

Check to see if emp# is greater than or equal to 400
If it is, then return a sum of all the salaries.
If not, then return 0.


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