Search code examples
crystal-reports

Crystal Reports If true then return number else return NULL


In Crystal Reports, is it possible to have a function that returns a numeric value if the if statement evaluates to true and returns NULL otherwise?

I currently have

IF ({INDICATOR} = 'Y') Then
(
    {numeric value}
)
Else
(
    0
);

But since 0 is a possible value of {numeric value} it doesn't make sense. Rather, I would rather have that field come up blank if the indicator isn't 'Y', but when I replace the 0 with NULL it gives me a type mismatch error.

Is there a way for me to only show the value when the indicator is 'Y'?


Solution

  • you can't return two different datatypes in a single if statement..If if is number then else should also be number.. instead try to split the statements and try.. something like below.

     IF ({INDICATOR} = 'Y') Then
        (
            ToText({numeric value})
        )
    
       Else if ({INDICATOR} <> 'Y') Then
        (
           ""
        );