Tableau Funtion: PREVIOUS_VALUE( )
Tableau Function: PREVIOUS_VALUE( )
Category: Table Calculation Functions
Purpose
The PREVIOUS_VALUE() function in Tableau is a table calculation that returns the value from the previous row’s calculation result within a partition. Unlike functions such as LOOKUP(), it references the result of the calculation itself, not a value from the underlying data.
In simple terms, PREVIOUS_VALUE() answers:
“What was the value of this calculation in the previous row?”
Type of Calculations
Table calculations
Iterative calculations
Recursive-style logic
Running and cumulative computations
PREVIOUS_VALUE() is evaluated sequentially across rows in the view and depends on the calculation order.
Practical Use Cases
Creating running totals
Building custom cumulative metrics
Filling missing values (forward-fill logic)
Performing iterative calculations not possible with standard aggregations
Creating stateful calculations across rows
PREVIOUS_VALUE(expression)
| Parameter | Type | Description |
|---|---|---|
| expression | Scalar / Aggregate / Table calculation | Initial value returned for the first row and used when no previous value exists. |
How It Works?
Logical Principle
PREVIOUS_VALUE() evaluates calculations row by row:
For the first row, Tableau returns the expression value
For subsequent rows, Tableau returns the result from the prior row
The current row’s result can build on that value
This enables iterative logic, similar to a loop:
Current Value = PREVIOUS_VALUE() + IncrementWhat Does It Return?
Data Type: Same as the expression
Meaning:
Returns the value from the previous row’s calculation result
For the first row, returns the value of the expression parameter
When Should We Use It?
Use PREVIOUS_VALUE() when you need to:
Perform calculations that depend on earlier results
Build custom running totals or balances
Implement cumulative or state-based logic
Fill missing or sparse data sequentially
Go beyond standard table calculations
Basic Usage
Return previous calculation value
PREVIOUS_VALUE(0)
- Returns
0for the first row - Returns the previous row’s result for subsequent rows
Column Usage
Create a running total
PREVIOUS_VALUE(0) + SUM([Sales])
Adds current sales to the previous cumulative value
Forward-fill missing values
IF ISNULL(SUM([Sales]))
THEN PREVIOUS_VALUE(0)
ELSE SUM([Sales])
END
Carries the last known value forward
Advanced Usage
Custom running difference
IF INDEX() = 1 THEN 0
ELSE PREVIOUS_VALUE(0) + (SUM([Sales]) - LOOKUP(SUM([Sales]), -1))
END
Demonstrates advanced iterative logic
Cumulative growth calculation
PREVIOUS_VALUE(1) * (1 + [Growth Rate])
Useful for compounded growth modeling
Tips and Tricks
Always define sorting before using
PREVIOUS_VALUE()Use
INDEX()orFIRST()to control initial behaviorKeep expressions simple to avoid calculation loops
Incorrect sorting can produce misleading results
Overuse can impact performance on large datasets
Related Functions You Might Need
Functions commonly used alongside or as alternatives to PREVIOUS_VALUE():
LOOKUP()RUNNING_SUM()FIRST()INDEX()WINDOW_SUM()LAST()
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 returns the result of the previous row’s calculation within a partition.
PREVIOUS_VALUE() references the previous calculation result, while LOOKUP() retrieves data values.
It returns the value of the expression parameter.
Yes, it is evaluated after aggregation and depends on the view layout.
Yes, complex or large iterative calculations can impact performance.