Skip to main content
Version: 8.1

lookup

This function is used by Ignition's Expression language.

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.

Syntax​

lookup(dataset, lookupValue, noMatchValue, [lookupColumn], [resultColumn])

Parameters​

TypeParameterDescription
DatasetdatasetA dataset to search through.
ObjectlookupValueThe value to look for in the dataset.
ObjectnoMatchValueThe value to return if no match is found.
ObjectlookupColumnThe column to search for the lookup value. Can be the column index or name. Defaults to column 0. [optional]
ObjectresultColumnThe column to retrieve the result value from. Can be the column index or name. Defaults to column 1. [optional]

Returns​

Object - The value in the result column of the same row where the lookupValue was found, or the noMatchValue if no match was found. The data type of the result will always match the type of the noMatchValue.

Examples​

The examples are based of a table that has the following data in it:

ProductPriceCategory
"Apples"1.99"Fruit"
"Carrots3.5"Vegetable"
"Walnuts"6.25"Nut"
Code Snippet
lookup({Root Container.Table.data}, "Carrots", -1.0) //returns 3.50
Code Snippet
lookup({Root Container.Table.data}, "Grapefruit", -1) //returns -1, the noMatchValue
Code Snippet
lookup({Root Container.Table.data}, "Walnuts", "Unknown", 0, "Category") //returns "Nut"
Code Snippet
lookup({Root Container.Table.data}, "Pecans", "Unknown", 0, 2) //returns "Unknown", the noMatchValue