Introduction to Lookup Function in Tableau
This article will explore the Lookup Function in Tableau. The lookup function is one of the most important and widely used table calculations in Tableau and is used to find values from a selected range. As the
Introduction to Lookup Function in Tableau
This article will explore the Lookup Function in Tableau. The lookup function is one of the most important and widely used table calculations in Tableau and is used to find values from a selected range. As the name suggests it is used to lookup values within a table (partition) i.e. either from the start of the partition or from the end. The value fetched is based on the offset value which defines the position (either positive or negative) from the current row. The value (measure/dimension) which needs to be looked up is specified in the syntax and the position is based on the offset. Offset is something that specifies the number of addresses which is added to the base address to get an absolute address.
Difference between Excel Lookup and Tableau Lookup
Excel also provides the lookup feature in terms of vlookup and hlookup. However, lookup in excel is used extensively to extract the values from a different table while Tableau lookup will fetch the data from within the table based on the offset values.
The syntax for Lookup function: [expression, offset]
Expression: The first part of the function is the aggregate of measure or dimension that will be returned.
Offset: This refers to the number which will specify in which direction should tableau move (Positive or negative) and by how much from the current row value. That means it specifies the position to fetch the value specified in the first part. Offset basically refers to the distance in cells from the starting of the table or from the end of the table. It can be a hardcoded number, a parameter or a formula. If the offset is a negative value it will lookup the previous rows and if the value is positive it will lookup the upcoming row’s values.
Let’s understand this topic using working examples.
Data Source Being Setup
We have a sample dataset that has data about the unemployment numbers in the US for 5 years (2005-2010). It consists of unemployment numbers for different age groups for each month. The unemployment numbers are specified for both men and women separately.
- After launching Tableau, connect to the excel file mentioned above using the connect option on the Tableau landing page. Select the excel option and browse to your data file.
- Once the file is selected and opened, you will be navigated to the data source view of the tableau. In the data source tab, it displays how the data source is being set up and also displays the first 1000 ro