Returns |
Since the IN
function returns a Boolean value, it can be used as a function or a conditional.
Tip: When you select values in a histogram for a column of String type, the function that identifies the values on which to perform a transform is typically |
Tip: If you need the location of the matched value within the source, use the |
keep row: IN(brand, ['discount','mid','high-end'] ) |
Output: Keeps all rows in which the value in the brand
column is either discount
, mid
, or high-end
.
derive type:single value:IN(column_string, values_array) |
Argument | Required? | Data Type | Description |
---|---|---|---|
column_string | Y | string | Name of column or literal to locate in the column specified in the second parameter |
values_array | Y | array literal | Array literal of values to search |
Name of the column or literal to find in the second parameter.
'Hello, World'
).Required? | Data Type | Example Value |
---|---|---|
Yes | Column reference or any value | myColumn |
Array of values to search for the first parameter.
Required? | Data Type | Example Value |
---|---|---|
Yes | Array literal | 'Steve' |
Source:
You have the following source data on your products:
ProdId | ProductName | Color | Brand |
---|---|---|---|
P001 | T-shirt | white | discount |
P002 | pants | beige | discount |
P003 | hat | black | discount |
P004 | T-shirt | white | mid |
P005 | pants | black | mid |
P006 | hat | red | mid |
P007 | T-shirt | white | high-end |
P008 | pants | white | high-end |
P009 | hat | blue | high-end |
In the data, you notice an error. For the discount and mid brands, T-shirt color should be orange
. You need to fix it.
Transform:
In the Transformer page, you select the white
value from the histogram at the top of the Color
column. Among the suggestion cards, select the Set transform. For the first variant, all values are missing. Click Modify. The current transform is the following:
set col: Color value: NULL() row: Color == 'white' |
In the Preview, you can see that this transform matches all white
values in the column and replaces them with a null value. Since the replacement value is orange
, you can edit the transform so it looks like the following:
set col: Color value: 'orange' row: Color == 'white' |
This step looks better. However, it is replacing all instances of white
, including those for white pants (P008) and high-end T-shirts (p007), which should not be replaced. To fix, you must add conditions to the row
expression. First, add the following, which ensures that the transform only replaces for T-shirts:
set col: Color value: 'orange' row: (Color == 'white' && ProductName == 'T-shirt') |
Now, the Preview shows that only T-shirt values are being changed. The transform needs to be further modified to restrict only to the appropriate brands (discount
and mid
):
set col: Color value: 'orange' row: (Color == 'white' && ProductName == 'T-shirt' && IN(Brand, ["discount","mid"])) |
NOTE: It's possible to specify the brand restriction as |
Results:
ProdId | ProductName | Color | Brand |
---|---|---|---|
P001 | T-shirt | orange | discount |
P002 | pants | beige | discount |
P003 | hat | black | discount |
P004 | T-shirt | orange | mid |
P005 | pants | black | mid |
P006 | hat | red | mid |
P007 | T-shirt | white | high-end |
P008 | pants | white | high-end |
P009 | hat | blue | high-end |