Print Page | Close Window

if -then statement not showing in report.

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=20519
Printed Date: 06 May 2024 at 3:56am


Topic: if -then statement not showing in report.
Posted By: freakingeek
Subject: if -then statement not showing in report.
Date Posted: 27 Feb 2014 at 10:31am
Hello,

I have what seems like a simple issue. Yet, I cannot get my formula to show in the report. The header for this particular column is Gender. By default the report shows numbers representing the following - Male, Female, other or unknown.
I want the report to reflect the names that the numbers represent.
Here is my formula:
if {DDB_PAT_BASE.Gender}=1 then "Male"
else if {DDB_PAT_BASE.Gender}=2 then "Female"
else if {DDB_PAT_BASE.Gender}=3 then "Other"
else if {DDB_PAT_BASE.Gender}=4 then "Unknown"

I don't get any errors, but  the values don't change, they still show only the numbers in the report.

What am I doing wrong?



Replies:
Posted By: kevlray
Date Posted: 27 Feb 2014 at 10:56am
Did you replace the {DDB_PAT_BASE.Gender} in the column with the formula?


Posted By: hello
Date Posted: 27 Feb 2014 at 11:02am
Is the table field numeric or string?

If it's numeric, add this to the top:

stringvar gender_string;

In the formula add:

gender_string = "male" instead of just "male". Same for "female", "other", "unknown"

Then at the bottom:

gender_string


Posted By: hello
Date Posted: 27 Feb 2014 at 11:12am
Or, maybe you just need the little := thingy instead of =


Posted By: kevlray
Date Posted: 27 Feb 2014 at 1:04pm
The formula is not assigning a value, thus the := is not necessary.  I am still guessing that freekingeek just did not drop the formula on the sheet, still looking at the field.


Posted By: freakingeek
Date Posted: 28 Feb 2014 at 3:21am
I tried using the "stringvar gender_string;" but then it looks for a string value. The value in the table is numeric. If I look at the present output in the report, I have numbers 1-4 representing the sex of the patient. I want the sex to show as male, female, other or unknown.

The formula I used is from another report using the same table. I just changed the report name to match mine. It works in the other report.

So how do I get the report to reflect what I want as far as Gender goes?


Posted By: adavis
Date Posted: 28 Feb 2014 at 4:10am
You said you just renamed an existing report? So you haven't changed any of the report fields?

I think kevlray may be correct about the wrong field being in the report. Can you try just removing the field from the report and placing the formula field in its place?


Posted By: lockwelle
Date Posted: 28 Feb 2014 at 5:00am
as always, one simple way to debug a formula is to break it into pieces. in this case just showing the field...which will satisfy adavis and kevlray suspicions.

Since CR is a black box, the best we can do is make sure that what we think is happening actually is.


Posted By: hello
Date Posted: 28 Feb 2014 at 5:56am
stringvar gender_string;

if {DDB_PAT_BASE.Gender}=1 then gender_string := "Male"
else if {DDB_PAT_BASE.Gender}=2 then gender_string := "Female"
else if {DDB_PAT_BASE.Gender}=3 then gender_string := "Other"
else if {DDB_PAT_BASE.Gender}=4 then gender_string := "Unknown";

gender_string







PS:
I've never really been sure when to use the = or the :=
so I try it both ways.


Posted By: freakingeek
Date Posted: 28 Feb 2014 at 5:59am
So are you asking to see the field as it reflects in the report?
In the formula I am using the same table that exists in the database.

And the field I have in the report is the same as whats in the formula.

The formula I copied from the other report, is using the same table.




Posted By: freakingeek
Date Posted: 28 Feb 2014 at 7:07am
I tried :
stringvar gender_string;

if {DDB_PAT_BASE.Gender}=1 then gender_string = "Male"
else if {DDB_PAT_BASE.Gender}=2 then gender_string = "Female"
else if {DDB_PAT_BASE.Gender}=3 then gender_string = "Other"
else if {DDB_PAT_BASE.Gender}=4 then gender_string = "Unknown";

gender_string

Unfortunatly the results are the same. The gender field in the report still only shows the numbers assigned the to gender.



Posted By: freakingeek
Date Posted: 28 Feb 2014 at 7:18am
To answer an earlier question, I am not using an existing report. I created this report and I used a formula from another report that is using the same
"DDB_PAT_BASE" table.  


Posted By: DBlank
Date Posted: 28 Feb 2014 at 7:59am
Just to be clear.
When you create a formula field in the Field Explorer it does not alter the existing data. It is not like an update script. The formula field itself can be placed on the report canvas to display the result of the formula. At no point does any formula in crystal alter the source data.
SO if you place, on the detail section the original field "DDB_PAT_BASE.Gender" and the next to it the Formula field that references it you should see the the origianl numeric value with ther translation into text next to it.
If you place them side by side what is the result?


Posted By: lockwelle
Date Posted: 28 Feb 2014 at 8:04am
just as a note:
stringvar gender_string;

if {DDB_PAT_BASE.Gender}=1 then gender_string = "Male"
else if {DDB_PAT_BASE.Gender}=2 then gender_string = "Female"
else if {DDB_PAT_BASE.Gender}=3 then gender_string = "Other"
else if {DDB_PAT_BASE.Gender}=4 then gender_string = "Unknown";

gender_string

is missing the assignment operator...all the = should be :=

and as DBlank said, the gender field will always be the value from the database...only the formula will be different, because, again as stated, the data is not being changed, you are just changing how it is displayed with the formula


Posted By: freakingeek
Date Posted: 28 Feb 2014 at 8:29am
I am not trying to change the results of the information.
For example, changing a 1 to a 2. I am simply trying change the numeric output to show as something other then a numeric value. So one will only show as male, two will only show as female.

It sounds like I am not getting the formula to show on the table. Doesn't the formula automatically present itself on the report once it's in a readable format? If not how do I add it to the report?


Posted By: lockwelle
Date Posted: 28 Feb 2014 at 8:31am
you need to place the formula on the report.

we realize that all you want to do is to display male instead of 1.

the logic that has been posted would seem to this, so if the formula has been placed on the report where you want to display it (which we assume you have done) and it is not displaying the correct results...then we have been giving suggestions on how to correct the logic or how to debug your logic.

it also sounded from one of the posts that you thought the formula would update the data in the field so that it would display as desired (male instead of 1), which is not the case.

just trying to help


Posted By: freakingeek
Date Posted: 28 Feb 2014 at 9:18am
Got it. I wasn't dragging the formula into report.
Thank you!



Print Page | Close Window