I assume your straight table has some dimensions, right? These dimensions group your data records such that each line, i.e. the if() function, will evaluate to one unambiguous result, zero or one.
If you use your expression in a chart with no or other dimensions, you probably won't get a single answer to the if() statement, so the if() will return NULL, therefore you will get "no data to display".