Crystal reports sum - crystal-reports

I need the sum of two database fields. I use this formula field :
{dbfield1}+{dbfield2}
and if dbfield1 and dbfield2 are != from null in database the sum is showing, but if the dbfield1 or dbfield2 are missing(no data) the formula field is not showing.
how can I manage this in Crystal report?

Two options :
Either use the Convert Database Fields to Null option under Report Options, which will convert the numeric field nulls to zero and make your sum work, or
Use the IsNull function in your formula :
If IsNull({dbfield1}) And IsNull({dbfield2}) Then
0
Else If IsNull({dbfield1}) Then
{dbfield2}
Else If IsNull({dbfield2}) Then
{dbfield1}
Else
{dbfield1}+{dbfield2}

Related

hide rows with zero value -- crystal reports

I have the following table in Crystal Reports 2010:
Name------------Number----Line----Price-----InvoiceNum
CustomerX-------800---------2------$100----------1
CustomerX-------800---------4------$0-------------1
CustomerX-------800---------4------$0-------------1
CustomerX-------800---------4------$900----------1
CustomerX-------800---------3------$0-------------1
CustomerX-------800---------3------$0-------------1
CustomerX-------800---------3------$1900---------1
CustomerX-------800---------2------$0-------------1
CustomerX-------800---------2------$0-------------1
I want to suppress the rows that are duplicates and have $0 value, so I need somethings like this:
CustomerX-------800---------2------$100----------1
CustomerX-------800---------4------$900----------1
CustomerX-------800---------3------$1900---------1
At section expert if I use this formula for suppressing it will hide all rows that have Price as $0 value.
if {#Price}=0 then true else false
But I only want to hide the $0 value if there are duplicate Line numbers for same InvoiceNum.
I also tried this:
if ({#Price}=0 and {#Price}=previous({#Price})) then true else false
but it would not remove all of the zero-values, just a part.
Go Report >Selection Formula>Record then Select your Fields As is
{Supplier.ClosingBalance} <>0

Crystal reports selecting record that contain empty strings or "null"

I have a report that for a field called JobNo there are some records that have "null" as the the cell value and some that have an empty string "". there is another field called AccntNo that im also selecting by in the same selection formula.
This is what i have tried without success in the selection formula for crystal reports.
{accnt.accno} = "7015" and
{accnt.jobno} = "" or {accnt.jobno} isnull
any help is apreciated
Selection formula doesn't work as expected, sometimes.
I suppose that this will work
{accnt.accno} = "7015" and
( isnull({accnt.JobNo}) or {accnt.jobno} = "" )
First of all I put parenthesis on 'or' clause.
But, the strangest thing, is that isnull clause must be evaluated before other comparison clauses.

Crystal Reports Formula Logic

I am using Crystal Reports 2008 and cannot figure out the proper expression for suppressing fields.
In this case, say I have a pill diary.
{PILL.TYPE_ANTI_INFLAMMATORY}
{PILL.TYPE_PAIN_REDUCTION}
{#INTEGER_TYPE1}
{#INTEGER_TYPE2}
The first two elements from the data tables PILL are columns of pill types. The first one is a column of type of anti-inflammatory pills, the second pain reduction. These columns each contain unique information.
In the second two elements, is a column of integers either negative or positive. These are formula columns (date difference between two dates.)
My expression:
{PILL.TYPE_ANTI_INFLAMMATORY} = "Advil" or
{PILL.TYPE_PAIN_REDUCTION} in ["Tylenol", "Acetometaphin"] and
{#INTEGER_TYPE1} > 1 or
{#INTEGER_TYPE2} > 1
What I am trying to do is display any row in which ANTI_INFLAMMATORY is equal to Advil or PAIN_REDUCTION is equal to Tylenol or Acetometaphin while also one of the columns of integer type is greater than 1.
(
{PILL.TYPE_ANTI_INFLAMMATORY}="Advil" or
{PILL.TYPE_PAIN_REDUCTION} IN ["Tylenol","Acetometaphin"]
) and
(
{#INTEGER_TYPE1} > 1 or
{#INTEGER_TYPE2} > 1
)
IF ({PILL.TYPE_ANTI_INFLAMMATORY}="Advil" or {PILL.TYPE_PAIN_REDUCTION} IN ["Tylenol","Acetometaphin"])
AND
({#INTEGER_TYPE1} > 1 or {#INTEGER_TYPE2} > 1) THEN
FALSE ELSE TRUE

Crystal Report Formular always return Boolean

iN my Crystal Report i have two columns of currency data types. I want to add a formular to the column a . i.e "WHEN A CURRENCY IN A is > THAN B, THEN The value of A should euqal the value of B ". I wrote my formula as below
currencyVar formular := {ProcName.coll};
IF({ProcName.coll} > {ProcName.ref})
Then
formular = {ProcName.ref}
AND
IF({ProcName.coll} > {ProcName.ref})
Then
{ProcName.coll}= {ProcName.ref}
Both yielded the same boolean values.When I saved and named the formula above, i then insert the formula to my column . However, the result are all boolean True/False. I am ot sure how this happened i check the data type of the formula is indicating boolean as well.
This is because you're testing equality not assigning the value as you wish to do. Change your last line to a statement of assignment by adding a colon before the equal sign:
...
formular := {ProcName.ref}
// ^

Conditionally sum in variable expression in total column

I'm building a report in iReport 5.0.4, so far I have a crosstab table as follows
What I'm trying to do in Total 4 is having a total of sum3Measure but only of types "X" or "Y" (defined by the value in $V{col1}). I tried in Text Field Expression this:
$V{col1}.equals("X") || $V{col1}.equals("Y") ? $V{sum3Measure } : 0
but it returns always null. I did:
$V{col1}.equals("X") ? $V{sum3Measure } : 0
to test if the operator || is not valid but it returns null as well.
I used $V{row1} instead of $V{col1} to test it wasn't a problem different from the expression, it did the sum.
All measures are defined with Calculation type Sum
Is it possible to do what I want? if not, is there a workaround I can try?
Any help will be appreciated, if you need more info just let me know.