Improved If functionality

Right now, there’s a pattern I would like to be able to use with the If function that I cannot seem to do. The pattern is this:

Let’s say have a Variable I want to test with a conditional. For simplicity, let’s say Variable = 1.

The way to test a conditional is with If(Variable>0, true, false)

But I often want to invoke Coda’s special chaining like:
Variable.If(>0, true, false)

I’d also like to be able to return the value of the Variable with:
Variable.If(>0, Value, false)

This second part could be especially useful when Variable is something really convoluted like a long formula.
My pattern right now is:
If(ReallyLongFormula.isBlank(), ReallyLongFormula, "Some text")

Instead it could be:
ReallyLongFormula.If(Value.IsBlank(), Value, "Some text")

This might not seem like much, but imagine a formula like this needing to be used twice:
[Unit Actions].[Unit Type].Unique().FormulaMap(If(CurrentValue.In(Units.[Unique Unit Name].Unique()).Not(),CurrentValue,"-")).Split(",")

(btw, I may be using the attribute Value wrong, and in that case just mentally replace it with a better name like self or whatever)

You can’t do this with Filter() without using additional named variables, or if you can I don’t know how.

1 Like

Hey @cnr, I hear what you’re saying. This is similar to how IFERROR() work in Excel, where the formula could be shortened by something like this: IFERROR(ReallyLongFormula, "Some Text"). This doesn’t account for values <= 0, unfortunately.

The workaround for me (in Coda) is simply giving the long formula a name so that you can reference that name in the IF() function:

2 Likes

Hi @Al_Chen_Coda, I think this would be a really useful reminder for new folks like me, but unfortunately the screenshot is now dead. Is there a chance you could refresh it?
Thanks!

@Samuel_Davenport Sure thing just re-uploaded the image, not sure why it disappeared. Let me know if you have any questions!

@Al_Chen_Coda

I have met the same situation and i think about iferror() in Excel.
Now, could I give the long formula a name in new update of coda ?

Hi @Loi_Quang_Ho, yes you could always give formulas in Coda a name. See this help article for more info.

Hi @Al_Chen_Coda

I can name a formula on the writing canvas.
Sorry if I missed something, I can not do it in the table. Please have a check.

Correct you can’t name formulas in tables.

1 Like

@Loi_Quang_Ho You can achieve similar results by making a new column with the long formula, and then using that column in your second formula!

2 Likes