How to insert formula for data type that has ">" / "<" symbols

Hi @nuraqlima , I’ve uploaded a workflow here

As you could have an undefined number of columns that need to be calculated in this way, It uses String Manipulation (Multi-Column) to act on all the String columns. As it is not possible to automatically have String Man (mult) act only on String columns, some additional nodes are needed to pass just the String Columns to that node, and then re-build the table afterwards, so the workflow is more involved than it ought to be!

However, the primary work for the calculations is this rather horrible looking script in String Manipulation (Multi Column):

string(	
$$CURRENTCOLUMN$$==null  
?$$CURRENTCOLUMN$$ 
:substr($$CURRENTCOLUMN$$,0,1).equals("<")
	?string(toDouble(substr($$CURRENTCOLUMN$$,1)) / 2)
	:substr($$CURRENTCOLUMN$$,0,1).equals("<")
		?string(toDouble(substr($$CURRENTCOLUMN$$,1)) / 2 + 1)
		:$$CURRENTCOLUMN$$
)

In the above “?” means “then” and “:” means “else”
So what this says is:

return a string such that:

if currentcolumn value is null (i.e. missing)
--then: return the currentcolumn value (i.e. leave it as missing)
--else: 
----if the first character (position 0) of current column value is "<"
------then: convert everything from the second character (position 1) onwards to numeric and divide by 2
------else: 
--------if the first character (position 0) of current column value is ">"
----------then: convert everything from the second character (position 1) onwards to numeric and divide by 2 and add 1
----------else: return the current column value unchanged

(further info on this syntax - see “conditional expressions” section of String Manipulation’s “undocumented” features)
After this node, it passes the result to String to Double to convert the values to Double.

btw, this node could have also returned Double by wrapping the whole script in the toDouble() function except that this won’t work if there is a chance you have missing values, since the toDouble() function breaks if it is passed “null”. So it is safer to do the string to number conversion separately.

2 Likes