Crystal Reports Conditional Rounding - crystal-reports

I just started learning Crystal Reports, and am using the below formatting formula:
local numberVar result;
if GroupName ({SCD_CUSTOMER.NAME}) = "32 Bar Blues, LLC" Then
(
result = round({PTS_PRI_ORDER_PRICING.SELLING_PRICE}, 2);
result;
)
Else defaultAttribute
For a while I didn't have the Else statement there, and I couldn't understand why the report would round ALL selling_price values, rather than just those for 32 Bar Blues, LLC.
Sticking the Else in fixed my issue, but I still don't understand it. Why is the round being executed when it should never even be looked at for scd_customer.name != 32 Bar Blues, LLC? What am I missing here?

There are couple of things possible first one is you are comparing string so it can be possible you have written wrong string name
Its a blind guess try to use below statement in "IF"
if GroupName ({SCD_CUSTOMER.NAME}) == "32 Bar Blues, LLC" Then

Related

i can't show space in formula in Crystal Report

I use this code to show the sum of my bank
if {?Bank} = {Bank.sum} then {#1} else 0
I have 6 bank accounts and when the bank = Bank has operations, then I show the sumand else I do not show anything.
I do not want to show "0" in my report.
I want to show " "(space), but when I change it to " ".
When I do it, I get the error
A number is required here
How can I fix it?
In that case, use:
if {?Bank} = {Bank.sum} then ToText({#1},0) else ""
The 2nd arg indicates zero decimal points. See online documentation of the ToText() function.
One option:
if {?Bank} = {Bank.sum} then ToText({#1}) else ""
Another option is to use formatting.

Crystal - Split string based on carriage return

I have a field like this, where I only want the first/latest entry to show on the Crystal report:
05/01/2018 00:00:00 pm notes
04/01/2018 00:00:00 pm more notes
03/01/2018 00:00:00 pm even more notes
Here's the code I have been trying to work with, but I get an error of "a subscript must be between 1 and the size of the array." Can someone please help point me in the right direction?
stringvar array csl;
stringvar return;
csl:=split({table.field},chr(13));
//csl[1]
if isnull({table.field}) then return:= ""
else return:=csl[1];
return;
The reason for the error is presumably because the check for null happens after the split.
I usually try to avoid using arrays/variables in Crystal Reports. Mainly because you can't group or use aggregate functions on formulas that contain variables.
So here's a solution that works with string-functions:
First Entry
If InStr({table.field}, chr(13)) > 0 Then
Left({table.field}, InStr({table.field}, chr(13)))
Else
{table.field}
Last Entry
If InStrRev({table.field}, chr(13)) > 0 Then
Right({table.field}, Len({table.field}) - InStrRev({table.field}, chr(13)))
Else
{table.field}
EDIT
To get the second line too you have to do the InStr/InStrRev two times:
First Entry
If InStr(InStr({#table.field}, chr(13))+1,{#table.field}, chr(13)) > 0 Then
Left({#table.field}, InStr(InStr({#table.field}, chr(13))+1, {#table.field}, chr(13)))
Else
{#table.field}
Last Entry
If InStrRev({#table.field}, chr(13), InStrRev({#table.field}, chr(13))+1) > 0 Then
Right({#table.field}, Len({#table.field}) - InStrRev({#table.field}, chr(13),InStrRev({#table.field}, chr(13))-1))
Else
{#table.field}

Summing Only Visible Rows in SSRS

I'm trying to sum only the visible rows for a report and I know the format is:
=Sum( iif( <use the condition of the Visibility.Hidden expression>, 0, Fields!A.Value))
In my report, I've set row visbility to:
=IIF(CInt(Fields!EM_ET.Value)=1 Or CInt(Fields!EM_ET.Value)= 2,True,False)
Not exactly sure what I'm missing, but when I use this as an expression:
=Sum(IIF(CInt(Fields!EM_ET.Value)=1 Or CInt(Fields!EM_ET.Value)= 2,True,False),0,Fields!EM_ET.Value)
I get this following error: Value expression for textrun'FTD1.Paragraph[0].TextRuns[0]' has a scope argument that is not valid for aggregate function.
You are giving the True/False as output to the SUM() from your expression.You need to change your expression as,
=Sum(IIF(CInt(Fields!EM_ET.Value) = 1 Or CInt(Fields!EM_ET.Value)= 2,0,Fields!EM_ET.Value))
Thanks coder of code.
I am getting some error message if i am using '0', so i replaced with nothing it's working. I thought it would be helpful.
=SUM(IIF(ISNOTHING(Fields!value1.Value) OR ISNOTHING(Fields!value2.Value),NOTHING,Fields!value1.Value))
I was having similar issues. I know this question has a marked answer, however it isn't entirely correct.
The following contains the code from the "marked correct" answer:
=Sum(IIF(CInt(Fields!EM_ET.Value) = 1 Or CInt(Fields!EM_ET.Value) = 2,0,Fields!EM_ET.Value))
The following snipit of code contains the code from above, with a slight tweak:
=Sum(IIF(CInt(Fields!EM_ET.Value) = 1 Or CInt(Fields!EM_ET.Value) = 2,NOTHING,Fields!EM_ET.Value))
By changing the "0" to "NOTHING" this will resolve any lingering issues with your formula. The formula I was having issues with was returning "#Error" in the cell that was supposed to return the sum of the visible cells in the column within the row group.
My formula originally looked like this:
=IIF(Sum(Fields!VCBitType.Value) <> 0 OR (Parameters!Details.Value = "Detail"), Sum(IIF((Fields!VCBitType.Value = 0) and (Parameters!Details.Value = "Dangerous"),0,Fields!VC.Value)), "")
I altered my formula after seeing Hari's comment above:
=IIF(SUM(Fields!VCBitType.Value) <> 0 OR (Parameters!Details.Value = "Detail"), SUM(IIF((Fields!VCBitType.Value = 0) and (Parameters!Details.Value = "Dangerous"),NOTHING, Fields!VC.Value)), "")
I wanted to set the cells value to "" (empty) rather than hide the cell entirely or set that cell's value to "0" in my report (due to the fact that not displaying the cell entirely made the report look really funky). Because I did this, using a "0" in my formula conflicted with the value of the cell which was "" (empty), causing the formula to break. The only change I made was to alter "0" to "Nothing", this resolved the issue I was having with the cell's formula.

Crystal Report Counting

My question is similar to the link.
Crystal Reports - Count Formula
The answer only works when the certain status type is giving to you.
Now I am wondering that what if the status type is not giving to you (You dont know what's inside this filed first), and the type of the status can be varied based what's in {statustype} field.
And I want to be able to list all distinct status type and calculate it's total appearance in the report.
Well its easy if you see it my way, I read that thread which you referenced.
Make different Formulas for all the status types that you may know of, I am pretty sure that they will be maximum 4 or 5. Make formula like
localvar int x;
if(statustype = 'Accepted')
(
x = x++;
)
x;
Or you can put all the formulas to one, using the same if clause but changing the display string, make sure that its a summary field or is placed at the report footer.
localvar int accept;
localvar int reject;
localvar int Pending;
if(statustype = 'Accepted')
(
accept= accept++;
)
else if
(
reject = reject ++;
)
else if
(
Pending = Pending++;
);
"Accepted "+ accept + " Rejected " + reject + " Pending "+ Pending;
Hope this helps,
I figured out that a easy way that we can create a placeholder in main report for subreport. And we can make the manipulation in the subreport

sum field in crystal report

I have two text fields in crystal report, textA and textB.
What if I wanted through the formula editor (not via c# code) set a third field called textTot = textA + textB.
What is the correct crystal report syntax?
Thanks a lot.
The simplist formula is: ToNumber({TableName.TextA}) + ToNumber({TableName.TextB}).
However, it would be a good idea to first test whether the data is numeric (to avoid a runtime error):
Local NumberVar numericA;
Local NumberVar numericB;
If IsNumeric(Trim({textA}))
Then numericA = ToNumber(Trim({textA}))
Else numericA = 0;
If IsNumeric(Trim({textB}))
Then numericB = ToNumber(Trim({textB}))
Else numericB = 0;
numericA + numericB;