Print Page | Close Window

"IF ... AND" Statement Headaches

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21978
Printed Date: 02 May 2025 at 4:23am


Topic: "IF ... AND" Statement Headaches
Posted By: jabucket
Subject: "IF ... AND" Statement Headaches
Date Posted: 24 May 2016 at 10:40am
I am working with a formula where I need to use If and AND to look at two values in order to make a decision on the value. My formula looks like this:

if ({Orders.TargetDrugName} = "capecitabine") & ({Orders.Strength} = "150") then 287.99 else
if ({Orders.TargetDrugName} = "capecitabine") & ({Orders.Strength} = "500") then 1633.17 else
if {Orders.TargetDrugName} = "chlorambucil" then "952.82" else
if ({Orders.TargetDrugName} = "cyclophosphamide") & ({Orders.Strength} = "50") then 1718.11 else
if ({Orders.TargetDrugName} = "cyclophosphamide") & ({Orders.Strength} = "25") then 976.20 else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "100") then "No Cost Available" else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "140") then "No Cost Available" else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "20") then "No Cost Available" else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "50") then "No Cost Available" else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "70") then "No Cost Available" else
if ({Orders.TargetDrugName} = "dasatinib") & ({Orders.Strength} = "80") then "No Cost Available" else
if ({Orders.TargetDrugName} = "erlotinib hcl") & ({Orders.Strength} = "100") then 6213.88 else
if ({Orders.TargetDrugName} = "erlotinib hcl") & ({Orders.Strength} = "150") then 7028.34 else
if ({Orders.TargetDrugName} = "erlotinib hcl") & ({Orders.Strength} = "25") then 2281.12 else
if {Orders.TargetDrugName} = "everolimus" then 11151.95 else
if {Orders.TargetDrugName} = "hydroxyurea" then "No Cost Available" else
if ({Orders.TargetDrugName} = "imatinib mesylate") & ({Orders.Strength} = "400") then 9905.81 else
if ({Orders.TargetDrugName} = "imatinib mesylate") & ({Orders.Strength} = "100") then 8247.09 else
if {Orders.TargetDrugName} = "lapatinib ditosylate" then 5798.98 else
if {Orders.TargetDrugName} = "lenalidomide" then "No Cost Available" else
if {Orders.TargetDrugName} = "methotrexate sodium" then "No Cost Available" else
if ({Orders.TargetDrugName} = "nilotinib hcl") & ({Orders.Strength} = "150") then 9820.60 else
if ({Orders.TargetDrugName} = "nilotinib hcl") & ({Orders.Strength} = "200") then 9820.60 else
if ({Orders.TargetDrugName} = "sorafenib tosylate") & ({Orders.Strength} = "200") then 13755.12 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "100") then 717.26 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "140") then 1004.70 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "180") then 1291.75 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "20") then 143.53 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "250") then 640.75 else
if ({Orders.TargetDrugName} = "temozolomide") & ({Orders.Strength} = "5") then 35.88 else
if {Orders.TargetDrugName} = "thalidomide" then "No Cost Available";

In this formula, Crystal says I need a number in place of the last "if". I know I'm doing something wrong, but troubleshooting is proving to be a headache.

Thanks

Jeff



Replies:
Posted By: Valert16
Date Posted: 26 May 2016 at 1:09am
Crystal is throwing this error because you are returning different data types in the If.. Then ..Else sentences.
For exemple, you have conditions like
If {Orders.TargetDrugName} = "chlorambucil" then "952.82" ... --> String data type
and also
if ({Orders.TargetDrugName} = "cyclophosphamide") & ({Orders.Strength} = "50") then 1718.11 --> Number data tytpe

You must return the same data types in every If .. Then condition.

Also, I think you shoud replace the "&" operator by "and".



Print Page | Close Window