check values within a column
Hi everyone,
I'm trying to create an amount field based on some transaction values, I have used prepare recipe with this formula:
if(transaction_type.match('sale', 'credit') , amount ,0)
Can anyone help to make this fomula working? or to give an alternative ?
Operating system used: windows
Best Answer
-
Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 317 Dataiker
HI @obidakacem
,
Perhaps you can share an example row of your data and exactly what check you want to perform? It sounds like if the `transaction_type` column is either `sale` or `credit`, you want the column to contain `amount` and otherwise set the column value to 0.
The way match works is described here:match(string a, string or regexp) array of strings
Returns an array of the matching groups found in
<span class="pre">s</span>
. Groups are designated by () within the specified string or regular expression.<span class="pre">match('hello</span><span> </span><span class="pre">world',</span><span> </span><span class="pre">'he(.*)wo(rl)d')</span>
returns<span class="pre">["llo</span><span> </span><span class="pre">","rl"]</span>
From your description, I think you simply want to check if transaction_type is equal to sale or credit instead of returning a match. In that case, I think you could simply do:
if((transaction_type == 'sale' || transaction_type == 'credit'), amount, 0)Let me know if you have any further questions about the formula.
Thank you,
Sarina