lookup
Description
This looks for lookupValue in the lookupColumn of dataset. If it finds a match, it will return the value from the resultColumn on the same row as the match. If no match is found, noMatchValue is returned. Note: The type of the value returned will always be coerced to be the same type as the noMatchValue.
If lookupColumn is not specified, it defaults to 0. If resultColumn is not specified, it defaults to 1.
The examples are based of a table that has the following data in it:
Product |
Price |
Category |
"Apples" |
1.99 |
"Fruit" |
"Carrots |
3.5 |
"Vegetable" |
"Walnuts" |
6.25 |
"Nut" |
Syntax
lookup( dataset, lookupValue, noMatchValue, [lookupColumn], [resultColumn] )
Examples
lookup({Root Container.Table.data},
"Carrots"
, -
1.0
)
//returns 3.50
lookup({Root Container.Table.data},
"Grapefruit"
, -
1
)
//returns -1, the noMatchValue
lookup({Root Container.Table.data},
"Walnuts"
,
"Unknown"
,
0
,
"Category"
)
//returns "Nut"
lookup({Root Container.Table.data},
"Pecans"
,
"Unknown"
,
0
,
2
)
//returns "Unknown", the noMatchValue