Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Help with If Then formula Post Reply Post New Topic
Author Message
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Topic: Help with If Then formula
     Posted: 01 Jul 2010 at 11:23am
I am trying to add a condition to a selection formula using an If Then statement.

"KT/V DAUGIRDAS", "KT/V (DAUGIRDAS))", & "KT/V - [DOQI-DG]" are 3 possible values from the PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION table. For the purposes of this report, I want them all to just show as "KT/V DAUGIRDAS"

What I have written is:

if ({PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} = "KT/V DAUGIRDAS", "KT/V (DAUGIRDAS))", "KT/V - [DOQI-DG]" then "KT/V DAUGIRDAS" else
{PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION}

I am getting errors when I check the formula about missing commas or a boolean being required.

IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 01 Jul 2010 at 11:50am
There two ways, the easiest is to use the 'in' operator.
if ({PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} in ["KT/V DAUGIRDAS", "KT/V (DAUGIRDAS))", "KT/V - [DOQI-DG]"] then "KT/V DAUGIRDAS" else
{PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION}
otherwise you will have to repeat the comparision three times seperated by 'OR's.
if ({PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} = "KT/V DAUGIRDAS" OR ({PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} ="KT/V (DAUGIRDAS))" OR ({PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} = "KT/V - [DOQI-DG]" then "KT/V DAUGIRDAS" else
{PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION}


IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 02 Jul 2010 at 3:48am
Thanks for your help. When I place the first example you wrote and check the formula by clicking the "X-2" button, I get an error that "The ) is missing" and on the formula the word "then" is highlighted in blue. I get the same if I use the 2nd or longer example.

I tried adding a close parenthesis right before "Then" but when I check the formula after doing so, I get a error "A boolean is required here." And the entire formula is highlighted in blue.



IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 02 Jul 2010 at 4:35am
I just noticed that there was a left parans right after the IF that should not be there (I wonder how that slipped in).  Otherwise I believe the syntax is correct.
if {PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION} in ["KT/V DAUGIRDAS", "KT/V (DAUGIRDAS))", "KT/V - [DOQI-DG]"] then "KT/V DAUGIRDAS" else
{PATIENT_LAB_RESULTS.FOREIGN_ANALYTE_DESCRIPTION}
Also, I am making the assumption that FOREIGN_ANALYTE_DESCRIPTION is a string value
IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 02 Jul 2010 at 4:58am
Thanks again. Yes, FOREIGN_ANALYTE_DESCRIPTION is a string.
I added the statement without the left paranthesis to the existing select statement and now it's giving me a message that "A boolean is required here." With the the entire new statement highlighted in blue.

Here is the original select statement:
{PATIENT_LAB_RESULTS.FACILITY_CODE} = {?Facility Number} and
{PATIENT_LAB_RESULTS.LAB_TEST_RESULT} <> "****" and
{MIMS_USER.MIMS_USER_ID} = {?mimsuser} and
{PATIENT_LAB_RESULTS.LAB_DATE_TIME} in {?Start Date} to {?End Date} and
{PATIENT_LAB_RESULTS.PROCEDURE_CODE} in ["20908", "22704", "10835", "1096", "1142", "1220", "12303", "1367", "1375", "1471", "15351", "28728", "1470"] and
{MIMS_USER_FACILITY.FACILITY_CODE} = {?Facility Number} and
{MIMS_USER_FACILITY.ACTIVE_Y} = "Y"


I added "and" to the end of the original and then the statement the you wrote.
IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 02 Jul 2010 at 8:03am
Thanks, I figured it out.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum