Search code examples
crystal-reportsconditional-statements

formula field in crystal report not working well when if condition is apply.how i solve the issue?


I have three columns in which two columns (Available and Minimum Level) are from dataset and third column (Status) is a formula field. My requirement is that when available is greater than minimum then status would "NO" else "YES". I make formula as following:

if {DataTable1.available}>{DataTable1.minimum} then
    "NO"
else 
    "YES" 

Its output displays below figure. It works well when available "0". If more than "0" then not working well as it shows in red area. It should display "YES" because available is less than minimum.

enter image description here


Solution

  • It looks like the values you are comparing are string values, not numeric values.

    You can convert the string values to a numeric value using ToNumber:

    IF ToNumber({DataTable1.available}) > ToNumber({DataTable1.minimum}) THEN
      "NO"
    ELSE
      "YES"
    

    You can also define the columns available and minimum of DataTable1 with a numeric data type.