Search code examples
crystal-reportscrystal-reports-2008

Null checking formula returns no output


I'm trying to display a 1 when both columns in a row are populated, and display a 0 otherwise. Since a formula field cannot refer to itself, I created two formula fields called notnull and notnull output

Notnull looks like this:

If NOT(isnull({Column1})) and NOT(isnull({Column2}))
then {@notnull output} = '1'
Else {@notnull output} = '0'

When I put this into my design, all the fields are blank. I want the output to look something like this table below. How can I fix this?

Column1    Column2    notnull output
 foo                        0
 bar         baz            1
             qux            0
 quux                       0
 gorge                      0
 foo         baz            1
 gorge       foo            1

Solution

  • Remove notnull and rewrite notnull output to look like this:

    IF ISNULL({Column1}) OR ISNULL({Column2})
    THEN '0'
    ELSE '1'
    

    While it's true you can't put a formula inside itself, you don't need to! Just put the desired return values in the Then/Else clause and notnull output will display them by itself. This works with any return type; Booleans, characters, strings, dates, etc.