Tableau Funtion: LOOKUP( )
Tableau Function: LOOKUP( )
Category: Table Calculation Functions
Purpose
The LOOKUP() function in Tableau is a table calculation used to reference values from other rows within the same partition. It allows you to retrieve a value from a row that is a specified number of positions before or after the current row, based on the view’s sort order.
In simple terms, LOOKUP() answers:
“What is the value in another row relative to this one?”
Type of Calculations
Table calculations
Offset-based calculations
Relative row comparisons
Time-series and trend analysis
LOOKUP() operates after aggregation and depends on the layout, sorting, and partitioning of the view.
Practical Use Cases
Calculating period-over-period differences
Creating running or cumulative comparisons
Comparing current values to previous or next values
Performing trend, variance, and growth analysis
Supporting advanced calculations with
FIRST(),LAST(), orINDEX()
LOOKUP(expression, offset)
| Parameter | Type | Description |
|---|---|---|
| expression | Aggregate or table calculation | The value to retrieve from another row. Must be aggregated when used in a view. |
| offset | Scalar (integer) | Number of rows away from the current row to reference. Negative values look backward; positive values look forward. |
How It Works?
Logical Principle
LOOKUP() retrieves a value based on relative position:
LOOKUP(expression, offset)It does not search by key or value. Instead, it:
Identifies the current row
Moves the specified number of rows forward or backward
Returns the value of the expression at that position
Example Formula
SUM([Sales]) - LOOKUP(SUM([Sales]), -1)
Calculates the difference between current and previous sales
What Does It Return?
Data Type: Same as the
expressionparameterMeaning:
Returns the value of the expression from a row at the specified offset
Returns
NULLif the referenced row does not exist
Offset Behavior
| Offset | Meaning |
|---|---|
-1 | Previous row |
0 | Current row |
1 | Next row |
When Should We Use It?
Use LOOKUP() when you need to:
Compare values between rows
Calculate growth or change over time
Reference prior or future records
Perform advanced table calculations
Build custom trend or variance logic
Basic Usage
Get the previous row’s value
LOOKUP(SUM([Sales]), -1)
- Returns the sales value from the previous row
Column Usage
Period-over-period change
SUM([Sales]) - LOOKUP(SUM([Sales]), -1)
Common for month-over-month or year-over-year analysis
Advanced Usage
Compare current value to the first value
SUM([Sales]) - LOOKUP(SUM([Sales]), FIRST())
Uses FIRST() to dynamically reference the first row
Compare current value to the last value
SUM([Sales]) - LOOKUP(SUM([Sales]), LAST())
Useful for end-of-period variance analysis
Custom running difference
IF INDEX() = 1 THEN 0
ELSE SUM([Sales]) - LOOKUP(SUM([Sales]), -1)
END
Prevents NULL values for the first row
Tips and Tricks
Always define sorting explicitly
Verify Compute Using settings
Handle
NULLvalues when offsets exceed boundariesCombine with
FIRST()orLAST()for dynamic offsetsLOOKUP()does not work without a visible viewCannot be used in row-level or LOD expressions
Related Functions You Might Need
Functions commonly used alongside or as alternatives to LOOKUP():
FIRST()LAST()INDEX()PREVIOUS_VALUE()RUNNING_SUM()WINDOW_SUM()
We’ve got plenty of resources to help you master Tableau functions. For more details, check out the official Tableau documentation. Or, if you’re ready for more practice, let’s dive into related functions and build your Tableau skills further!
If you’re ready to harness the full power of Tableau and elevate your data analytics capabilities, our expert Tableau consulting services are here to guide you. Whether you need support with building advanced calculated fields, creating dynamic visual dashboards, or optimizing your data sources for peak performance, our team of experienced Tableau consultants delivers customized solutions designed for your business needs. Visit our Tableau Consulting page to discover how we can help your organization turn data into impactful, insight-driven decisions.
It retrieves a value from another row based on a relative position (offset).
LOOKUP() returns NULL.
Yes, sorting determines which rows are before or after the current row.
Yes, it is evaluated after aggregation and depends on the view layout.
Yes, it is commonly used for period-over-period comparisons.