Define a function/expression ONCE to use across the table

There’s a maAny-columned table (dwelling rental with communal payment concerns) where i have to ensure correct data input with previous months comparison & so forth.
The thing is within single table i have to re-define just the same function (say to define previous row, in dynamically filtered list) to make appropriate calculation for another column, and here three columns depend on (and run) the same function to go on which i think may cause considerable overhead and slow/sluggish behavior.
I’ll readily provide the whole example (picture) if needed, but for now below give an instance of that function repeated over 3 columns:
prev = OplataRenty.lookupOne(Dwelling=rec.Dwelling, SN=(rec.SN-1))
apart from the rest of calculations that depend on the variable above

Now the question is if it possible to define “table-scoped” functions to reuse, which would be great ? :slight_smile:

Oh, by the way: $SN field above is kinda “sequential number” (basically row number for filtered records) cos obviously $id fields here not much helpful

You could create a column named Prev with the formula

OplataRenty.lookupOne(Dwelling=rec.Dwelling, SN=(rec.SN-1))

and then use $Prev whenever you need that value. If you make set that column’s type to be a Reference, then Grist can also help with autocomplete suggestions when entering $Prev in formulas. You are free to hide the column since it’s only needed in formulas, and you’ll still be able to see it in Raw Data for when you need to modify it.

Yeah, wonderful, magically it just hasn’t come to my mind… Thank you !)