Simple way to ifexist

Maybe a silly question, but does anyone know how to create a simple formula: if it exists, then 1, otherwise 0? The formula below always returns the second option even when the data grid variable is empty.

I want to change the color of a elements if the variable I use to fill a object is empty or not

Capture d’écran 2024-07-30 à 16.22.35

I tryed something with if (Ifempty({variable},0),color1(notempty),color2(empty)) but it doesnt seems to work as intended

Thanks in advance!

Your object is never null, but it can be empty. So you can check, if there are keys inside the object like this:

Bildschirmfoto 2024-07-31 um 10.59.24

No need for crazy formulas, null evaluates to false in a boolean context

I suggest you check out my blog post about this, it’s under Booleans - truthy and falsy values.

Hi @Broberto,

an empty Array [] or an empty object {} do not evaluate to false. So to find out, if there are items in there, it’s best to check their length.

You should fix that in your article.

Yes I actually know about this, someone on Reddit also suggested that as well, but I haven’t had time to fix it (yet), I’ll fix it tho, thanks :pray:

1 Like