Temporary variables in formulas
It would be amazing if you could implement a function that allows you to set a temporary variable to use within a formula! Something like the syntax used in OpenRefine's "with()" control (borrowing their syntax for my example - link to their wiki below).
Syntax:
WITH( [Function A], [Variable Name: string], [Function B] )
[Function A] would get evaluated first, and then the result could be referenced within [Function B] using the [Variable Name] string (essentially as if it was a named range). With this you can reuse a value in a formula multiple times without needing to repeat the function.
This would:
- eliminate (or at least reduce) the need to create helper cells / columns
- reduce the need to write long, messy, complicated formulas that repeat the same function calculations
- lower the amount of overhead when parsing formulas
Here's an example. This is using a pretty simple formula just that returns a status string output. Granted, theres a bunch of ways to do this, but just for illustration:
Current possible method 1 - repeating formula:
target cell:
=IF(A4="OUT","excluded in "&IF(ISERROR(MATCH(B4,Sheet2!$C:$C,0)),"both","list A but included in list B (!)"),IF(ISERROR(MATCH(B4,Sheet2!$C:$C,0)),"included in list A but excluded from list B (!)",""))
Current possible method 2 - helper cell:
helper cell (C4):
=ISERROR(MATCH(B4,Sheet2!$C:$C,0))
target cell:
=IF(A4="OUT","excluded in "&IF(C4,"both","list A but included in list B (!)"),IF(C4,"included in list A but excluded from list B (!)",""))
Proposed method - using "with" function:
=WITH(IF(A4="OUT","ex","in"),"var1",WITH(IF(ISERROR(MATCH(B4,Sheet2!$C:$C,0)),"ex","in"),"var2",IF(var1=var2,IF(var1="ex","excluded in both",""),var1&"cluded in list A but "&var2&"cluded in list B (!)")))
https://github.com/OpenRefine/OpenRefine/wiki/GREL-Controls#withexpression-o-variable-v-expression-e

1 comment
-
Jon Wittwer commented
Hurray for the new LET function !!!!
https://support.office.com/en-us/article/let-function-34842dd8-b92b-4d3f-b325-b8b8f9908999