Crystal Reports/FormatEditor/Display String formula: How to format data - crystal-reports

I want to specify a formula for the display string property of an object on my report, however I want to use it to format the data that would otherwise show up if I were not using this formula. Is there a keyword or anything I can reference within the formula that represents what would normally be displayed?

You might need to create a formula field and reference your database field within it:
for summarized fields, I use min(#cellVal) in the crosstab:
dim cVal as number
cval = {vw_rpt_waitlist.CountOfRecipientID}
if cval < 0 then
formula = " "
elseif cval = 0 then
formula = ""
elseif cval < 5 then
formula = "< 5"
else
formula = cstr(cval,0,",")
end if
and in the rows list, to modify the sorting:
if {vw_rpt_waitlist.SupportCode} < 100 then
formula = {vw_rpt_waitlist.description}
else
formula = "z" + totext({vw_rpt_waitlist.SupportCode}) + {vw_rpt_waitlist.description}
end if

It doesn't seem this is possible as far as I've been able to tell.

Related

How to join a string and float value in a calculated field using Tableau?

I am trying to create a calculated field where the output is "x% Over the Goal", however cannot due to string and float values. Essentially, what I want is the following:
IF Actuals > Goal THEN Actuals/Goal+'Over Goal'
ELSEIF Actuals < Goal then Actuals/Goal+'Under Goal'
ELSE 'At Goal' END
Is something like this possible? I've tried creating two separate calculated fields and concatenating them, but that does not work either.
Any help would be greatly appreciated.
You Can achieve this in a single calculated field:
IF [Actuals] > [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Over Goal"
ELSEIF [Actuals] < [Goal] THEN STR(FLOAT([Actuals] / [Goal])) + "Under Goal"
ELSE "At Goal" END

Crystal Reports If Any Record Meets Condition, Exit Formula

I wish to create a formula that will read each record, and if a certain condition is met then the formula will stop reading records and return a specific label. I have tried the following code and the correct result is displayed at the detail level but not the footer. It appears the "exit for" isn't really working. Thanks for your help!
Current Code (I have placed in the report footer):
shared stringvar label := "";
local numbervar i;
for i := 1 to {#Count_Records} do
(
if ({report_data.return_code}[i] = "defective-exchange"
or {report_data.return_code}[i] = "defective") then
label := "Defective-Exchange Only";
exit for;
);
if label = "" then
label:="Pickup Credit Memo";
label;
To eliminate data, use a record-selection formula:
{report_data.return_code} = "defective-exchange" or {report_data.return_code} = "defective"
To format data, use a formula field:
// {#Return Code}
if {report_data.return_code} = "defective-exchange" or {report_data.return_code} = "defective" then
"Defective-Exchange Only"
else if {report_data.return_code} = "" then
"Pickup Credit Memo"
else
"something else"

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;

sum two values from different datasets using lookups in report builder

I have a report that should read values from 2 dataset by Currency:
Dataset1: Production Total
Dataset2: Net Total
Ive tried to use:
Lookup(Fields!Currency_Type.Value,
Fields!Currency_Type1.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
This returns only the first amount from dataset 2.
I've tried Lookupset function as well but it didn't SUM the retrieved values.
Any help would be appreciated.
Thanks Jamie for the reply.
THis is what i have done and it worked perfect:
From Report Properties--> Code , write the below function:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
If (ct = 0) Then return 0 else return suma
End Function
Then you can call the function:
code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))
Yes, Lookup will only return the first matching value. Three options come to mind:
Change your query, so that you only need to get one value: use a GROUP BY and SUM(...) to combine your two rows in the query. If you are using this query other places, then make a copy and change that.
Is there some difference in the rows? Such as one is for last year and one is for this year? If so, create an artificial lookup key and lookup the two values separately:
=Lookup(Fields!Currency_Type.Value & ","
& YEAR(DATEADD(DateInterval.Year,-1,today())),
Fields!Currency_Type1.Value & ","
& Fields!Year.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
+
Lookup(Fields!Currency_Type.Value & ","
& YEAR(today()),
Fields!Currency_Type1.Value & ","
& Fields!Year.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2")
Use the LookupSet function as mentioned. With this you'll get a collection of the values back, and then need to add those together. The easiest way to do this is with embedded code in the report. Add this function to the report's code:
Function AddList(ByVal items As Object()) As Double
If items Is Nothing Then
Return 0
End If
Dim Total as Double
Total = 0
For Each item As Object In items
Total = Total + CDbl(item)
Next
Return Total
End Function
Now call that with:
=Code.AddList(LookupSet(Fields!Currency_Type.Value,
Fields!Currency_Type1.Value,
Fields!Gross_Premium_Amount.Value,
"DataSet2"))
(Note: this code was not tested. I just composed it in the Stack Overflow edit window & I'm no fan of VB. But it should give you a good idea of what to do.)

crystal formula to compare a string field and a number field

I'm trying to compare two fields that contain up to 2 digit field.
One formula field is a {string} the other to compare to is a {number} field.
But i"m running to a problem when the string field shows for example "08" and the number field shows "8" then it will show 1 that there is a differences but actually there is no difference. If the string field shows 14 and the number field shows 14 that works perfectly but anything between 1-9 will show a difference when actually there is no difference.
This is what I tried so far.
If {number.field} = 0
Then StringVar AdjustValue:= " "
Else StringVar AdjustValue:= totext ({number.field},0,"")
;
if {#stringfield} = StringVar AdjustValue then 0 else 1
Thanks in advance for the help.
Instead, convert from string to numeric so you don't have to worry about leading zeros.
if tonumber({#stringfield})={number.field} then 0 else 1
And just a quick side note: You are re-declaring the AdjustValue variable three times. There's no need to refer to it via "StringVar" after an initial variable declaration within the same formula.
EDIT: Since you're having problems with the top formula, you could also try the alternative of just padding your AdjustValue variable to two spaces:
stringvar AdjustValue;
If {number.field} = 0
Then AdjustValue:= " "
Else AdjustValue:= totext ({number.field},"00") //add padding
;
if {#stringfield} = StringVar AdjustValue then 0 else 1
Keep it simple with a formula field that will return a Boolean value:
// {#compare}
ToNumber({#string})={number.field}
Reference the {#compare} where ever you need it.