Let’s give another chance to the initiative — Brainstorm hours, where we want to have direct collaboration between our community and the team, and ask you to participate in the brainstorming session and share your thoughts on certain features.
Today’s topic: Formula Functions.
We know Modulus () is the most awaited one, and it will be added shortly. Which else functions to add to the Baserow formulas?
How about choosing one well designed and documented library (in python? or another language that fits the need) and have loaded and usable in formula cells?
field('field_name') and lookup('table_name', 'field_name') would then be the two extra things to add to the chosen library.
I indeed think about pandas as it is thought for working with tables, though it might be an overkill as right now formula cells only have access to the cells of the same row.
Giving access to the content of all cells to formulas would be a great thing.
@jibe-b Formulas under the hood are implementing using SQL. So unfortunately we can’t easily just plug in another python library and make it available in the formula language. Additionally the goal of the formula language is to make it a simple expression language that non-technical users can use. Somehow offering python code in formulas would go against this design goal.
Now perhaps in the future a Python field plugin might come along, which could do exactly what you describe. But we have no concrete plans for such a plugin/offering yet.
Separately there are potential future formula functions we could add that would allow accessing other cells. For example something like vlookup or some sort of table_join functions. But once again these aren’t on the current roadmap, but perhaps they will be soon :)?
An easier way to convert a boolean to a number would be nice. On several occasions, I’ve found myself wanting to to some sort of math operation (e.g. sum) on a variety of things that return true/false, and I first need to awkwardly use an if-statement to convert that to 1/0.
The following functions already exist and can be used today in Baserow out of your list:
trim
replace + regex_replace
lower is toLowerCase()
upper is toUpperCase()
slice and split do not exist yet. Can you provide some examples on how exactly they would work?
I believe you can use the existing left and right functions to slice up a string, but I agree a single “slice” function would be nice which possibly worked like this?
slice('abcde', 1,2) = 'bc'
slice('abcde', 0,5) = 'abcde'
Now for split I’m not sure how this would work currently if I’m assuming you mean “split this piece of text into a list of smaller pieces of text” as the formulas don’t exactly have a “list” type that you can work with not via link fields atm. But its certainly possible to add a first class “list” type to the formula language that could work like so:
Hm this is a great idea. We could extend the existing tonumber function that converts text → number to also allow converting a true → 1 and false → 0.
Ontop of that we could implicitly convert under the hood: sum(field('boolean lookup'))
into sum(tonumber(field('boolean lookup'))
And so with this implicit adding of “tonumber” sum would just work with booleans out of the box. Do you think this also would make sense? Or is it a bit too magic perhaps?
You could go even further and make the formula language allow things like:
1 + true = 2
But i think this potentially goes too far than just making sum work with booleans, and might result into users writing buggy formulas and not realizing it. Where-as having tonumber is more opt-in and hence less unexpected: 1 + tonumber(true) = 2.