This strikes me as an ugly pattern, however I don’t know a way to get around it.
I know how to handle the opposite:
categorySelector.IfBlank(...)
But there is no IfNotBlank formula. Also, _NoOp() is technically not supported, even though I use it in every doc at least 20 times. Anyone know a more elegant solution?
Hi @cnr ,
I second you: it’s not the best pattern ever and I use it a lot, too.
I didn’t find any better alternative, yet.
While not super-urgent, I’d like to see some shortcuts of else-less-if(s).
Something like DoIf() or DoUnless() (or naming variations like RunIf() etc…) that consider the default action is a _Noop().
Hi,
New here and no expert - so I could very much be misunderstanding your question. but isn’t it as simple as writing the following formula in your filter:
categorySelector.isBlank() OR [My Table ].[Category].Contains(categorySelector)
the OR operator means that the formula will always return true if the categorySelector is blank and thus the table will not filtered in that case. You can use a single formula to filter based on multiple controls using the same pattern and and outer AND operator:
(
someSelector.isBlank()
OR
[My Table].[someColumn].Contains(…)
)
AND
(
anotherSelector.isBlank()
OR
[My Table].[anotherColumn.Contains(…)
)
You are right and this actually let me understand I misread @cnr’s first post.
As a matter of fact, composition of conditions - as complex as you like - should allow to have a unique boolean output.
(@cnr: are we missing something, here?)
I took it for another anti-pattern I keep on running into, which is conditional actions: If(<condition>, RunActions(...), _Noop()).
This is the only way to achieve it, so far and it’s quite ugly to my sensibility without even taking into consideration _Noop() formula isn’t official.
Edit:
The only reservation I have about this approach is that I find it more complex to parse at a glance what a condition is doing when it contains many OR and AND tokens. I suppose with some formatting it’s a bit more readable.
(
someSelector.isBlank()
OR
[My Table].[someColumn].Contains(…)
)
AND
(
anotherSelector.isBlank()
OR
[My Table].[anotherColumn].Contains(…)
)
If logical operators could be chained then this might be an interesting pattern. Not sure it’s much more readable but at least operator preference is explicit.
Thanks for this! I’m new-ish to Coda and having from the drudgery of Excel, I had gotten myself used to accepting long horribly unreadable formulas, since excel doesn’t accept any formatting. I’m very happy to see just now that Coda’s formula editor preserves formatting - Yeay !
Yeah! It’s great. Thanks again for improving my approach!
Would you be interested in collecting:
(
someSelector.isBlank()
OR
[My Table].[someColumn].Contains(…)
)
and
SwitchIf(<condition>, RunActions(...))
into a single answer and I’ll mark it as your first solution in the Coda community? I think it would be useful to future readers to have them all in one post.