check values within a column

Solved!
obidakacem
Level 1
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

0 Kudos
1 Solution
SarinaS
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 s. Groups are designated by () within the specified string or regular expression.

match('hello world', 'he(.*)wo(rl)d') returns ["llo ","rl"]

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

View solution in original post

0 Kudos
1 Reply
SarinaS
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 s. Groups are designated by () within the specified string or regular expression.

match('hello world', 'he(.*)wo(rl)d') returns ["llo ","rl"]

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

0 Kudos