If function documentation


I could not find any documentation for the If function, other than this post from Gregori:
Type detection in ‘if’ statement - Issues - Community (datagrok.ai)
Could you please point me at the documentation, in case I missed it?

By experimenting with the function I could figure out that nested Ifs are supported; however, it seems that a function is not accepted as the result of the If clause evaluation. See the two examples below.

Example that works
I can create 3 calculated columns as follows:

  1. ModelPlusMinus: RegExpExtract (${Idea Tags}, "Model[+-]+", 0)
  2. DockPlusMinus: RegExpExtract (${Idea Tags}, "Dock[+-]+", 0)
  3. DockPlusMinusNA: if (IsNotEmpty(${ModelPlusMinus}), ${ModelPlusMinus}, if (IsNotEmpty(${DockPlusMinus}), ${DockPlusMinus}, "n.a."))

As expected, column DockPlusMinusNA contains Model+, Model-, Model+-, Dock+, Dock-, Dock+-, n.a. depending on the content of the intermediate columns ModelPlusMinus and DockPlusMinus.

Example that does not work
I cannot create a calculated column without using any intermediate columns with the following expression:
if (RegExpContains (${Idea Tags}, "Model[+-]+"), RegExpExtract (${Idea Tags}, "Model[+-]+", 0), if (RegExpContains (${Idea Tags}, "Dock+"), RegExpExtract (${Idea Tags}, "Dock[+-]+", 0), "n.a."))

Could you please confirm if the above is expected?

If so, it would be great if the If clause evaluation could support functions as the result, in addition to string constants or column titles, as it would remove the need to create intermediate columns.

Thanks in advance, kind regards


That’s an interesting question, thanks! We’re looking into that behavior.
Indeed, if we decompose the initial call, we’ll see that function calls work on their own (e.g. RegExpExtract), and the same is true for the “nested if” expressions that use constants as a replacement for the extraction calls: if (RegExpContains (${Idea Tags}, "Model[+-]+"), "Model", if (RegExpContains (${Idea Tags}, "Dock+"), "Dock", "n.a.")). It doesn’t look like the function support is disabled or not allowed by design, so we need to find the reason why complex expressions aren’t working.


Thank you Diana! BTW, there’s a typo in my complex expression above, it should actually read
if (RegExpContains (${Idea Tags}, "Model[+-]+"), RegExpExtract (${Idea Tags}, "Model[+-]+", 0), if (RegExpContains (${Idea Tags}, "Dock[+-]+"), RegExpExtract (${Idea Tags}, "Dock[+-]+", 0), "n.a."))

RegExpExtract was the culprit. It threw an exception if no match was found instead of returning null, which wasn’t a problem when called to create a column on its own, but obviously didn’t work inside the If function. I’ve checked the creation of a column using the full expression: if (RegExpContains (${Idea Tags}, "Model[+-]+"), RegExpExtract (${Idea Tags}, "Model[+-]+", 0), if (RegExpContains (${Idea Tags}, "Dock[+-]+"), RegExpExtract (${Idea Tags}, "Dock[+-]+", 0), "n.a.")). It works fine now.
In addition to this fix, we’ll add documentation for the function. I’ll post a link once it’s done.


Thank you, Diana, that’s great!

Here’s a link to our docs, as promised: