Crystal Reports 2016 Formula Syntax - crystal-reports

I am new to Crystal Reports.
I have a DB where the Memory Column is being reported in KB.
I created a report for my IT director in which he wants that field to be reporting the memory in GB.
I tried this formula (based on book I purchased titled 'Beginner's Guide to Crystal Reports 2016')
IF {tblDts.Memory} = "" THEN "N/A" ELSE {tblDts.Memory}*0.4256
The error I get is
A number, or currency amount is required here
and it highlights the {tblDts.Memory} after my ELSE statement.
That field in the database only has numeric values (btw - 0.4256 is the decimal format for 10240, I tried a division statement with the same results so I figured I try a multiplication statement).
What am I doing wrong?

In a conditional statement both IF and ELSE should return same datatype else there will be these kind of errors reported.
Here for IF you are returning string and for ELSE you are returning Number hence the error.
Suggested would be return 0 in case of IF and your calculation in ELSE
IF {tblDts.Memory} = ""
THEN 0
ELSE {tblDts.Memory}*0.4256
Edit--------------------------------------------------
if IsNumber({tblDts.Memory})
then
(
ToNumber({tblDts.Memory})*0.4256
)
else
0

Related

IIF or IF statement in Tableau

I am trying to write a IIF statement in Tableau to check if a condition passes. If it fails the condition, I want it to show "No values" rather than filtering out the row.
Given below is the IIF statement I am using:
IIF(([Average monthly count] > [Today]),[Average monthly count],"No values in the range")
As mentioned in comments, in Tableau isn't possible to return two different data types in IF or IIF statements, so if you really need to pass a string like "no values in range", you must return a string in true case. This can be done using the function STR as follows:
IIF(([Average monthly count] > [Today]),STR([Average monthly count]),"No values in the range")
Another option may be just return NULL in false case.
IIF(([Average monthly count] > [Today]),[Average monthly count],NULL)

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.

BIRT Report Tool

I created a Report using BIRT Report Design in Eclipse Java EE IDE(Juno Release).
In that Report, For the single row it have multiple values for the corresponding one column(I used LISTAGG() oracle function to map that).
(i.e.) Result column have multiple values in the below database table output :
No Name Result Mark
-----------------------------------
1 John X 32
XX
XXX
2 Joe X 56
XX
XX
XXX
3 Andrew 34
XXX
XX
XXXX
…
It have both NULL and NOT NULL values in it.
"If the NULL values are in the middle means its showing the results properly in the Report"
Sample Result am getting in Report output for Joe (.pdf form)
No Name Result Mark
-----------------------------------
2 Joe X 56
XX
XX
XXX
Here the problem is,
“If First record has a NULL means it is not showing properly in the Report, instead of that NOT NULL value will print in the front and so on…”
Sample Result am getting in Report output for Andrew (.pdf form)
No Name Result Mark
-----------------------------------
3 Andrew XXX 34
XX
XXXX
But we have TWO NULL values present in the Front of Result column for Andrew (As you see sample oracle table output above)…
Is there any option to show blank in the first row(if it is a null) for the particular row in the birt report tool ?
Kindly Help me to Solve this issue… Thank you!
While I did not try to understand exactly what your issue is, in general when null values in the data are causing problems with a BIRT report. Use one of these two solutions.
Use the data base function to convert the NULL to something else. In SQL I use the command ISNULL
Use a computed column in the BIRT 'Data Set' to create a new column, write whatever you need in JS. In the example below I need to make a decision on a date field that is sometimes null, in comparison to an input parameter.
if (row["START_TIME"] == null){
"F"
} else if (row["END_TIME"] == null){
"T"
}else if (row["START_TIME"].getTime() >= params["WeekOf"].getTime() ){
"T"
}else if(row["END_TIME"].getTime() <= params["WeekOf"].getTime() ){
"F"
}else if(row["END_TIME"].getTime() >= params["WeekOf"].getTime() ){
"T"
}else{
"F"}

How to return zero for a field in Crystal report

I am generating crystal report from database. My requirement is to when the field TKK Balance returns 0 or more than 0 for a row the report will print a dash '-' for that row and if it is less than 0 then only it will return the original value from the database. Is there anyone who can help me on this? please?
Thank you
First of all it can be done inside the SQL select statement like this
,(
CASE WHEN [TKKBalance] >= 0
THEN '-'
ELSE CONVERT(NVARCHAR, [TKKBalance])
END
) AS [SomeName]
or, you can create and use a formula field inside your report with the following code
if {TableName.TKKBalance} >= 0 then
"-"
else
totext({TableName.TKKBalance})

Crystal reports sum

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}