Tableau Funtion: LAST( )
Tableau Function: LAST( )
Category: Table Calculation Functions
Purpose
The LAST() function in Tableau is a table calculation that returns the relative position of the last row (or mark) in a partition. It tells you how far the current row is from the last row in the current partition, based on the defined sort order and computation scope.
In simple terms, LAST() answers:
“How many rows are between this row and the last row?”
Type of Calculations
Table calculations
Position-based calculations
Relative offset calculations
Order-dependent logic
Like FIRST() and INDEX(), LAST() is evaluated after aggregation and depends entirely on the view layout.
Practical Use Cases
Identifying the last record in a partition
Creating end-of-list logic
Comparing values to the final value in a series
Building custom filters (e.g., show last N rows)
Highlighting or labeling ending values in trends
LAST()
| Parameter | Type | Description |
|---|---|---|
| None | N/A | LAST() does not require parameters. Its output is determined by partitioning, sorting, and table calculation direction. |
How It Works?
Logical Principle
LAST() calculates the offset distance from the last row in the partition:
LAST() = Last Row Index − Current Row Index
Because Tableau counts backward rows as positive offsets:
The last row always returns
0Rows before the last return increasing positive integers
Example Formula
LAST() = 0
Identifies only the last row in each partition
What Does It Return?
Data Type: Integer
Meaning:
Returns
0for the last row in a partitionReturns positive integers (
1,2,3, …) for rows before the last
Example Output
| Row Position | LAST() |
|---|---|
| 1st | 3 |
| 2nd | 2 |
| 3rd | 1 |
| Last | 0 |
When Should We Use It?
Use LAST() when you need to:
Identify or isolate the final value in a sorted dataset
Compare values relative to the end of a partition
Filter or highlight ending records
Perform trend-end or closing value analysis
Build logic that depends on the last row
Basic Usage
Identify the last row
LAST() = 0
- Returns TRUE only for the last mark
- Useful for labels or conditional formatting
Column Usage
Label the last record
IF LAST() = 0 THEN "Last Record" ELSE "Other" END
Helps highlight the ending value in tables or charts
Advanced Usage
Compare each value to the last value
SUM([Sales]) - LOOKUP(SUM([Sales]), LAST())
- Calculates variance from the final value
- Common in performance or trend-end analysis
Tips and Tricks
Always define sorting explicitly before using
LAST()Verify Compute Using to control partition behavior
Combine with
LOOKUP()for end-relative calculationsLAST()values change if sort order changesNot suitable for row-level or LOD expressions
Related Functions You Might Need
Functions commonly used alongside or as alternatives to LAST():
FIRST()INDEX()LOOKUP()RANK()WINDOW_MAX()RUNNING_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 returns the number of rows between the current row and the last row in a partition.
Rows before the last row are counted as positive offsets relative to the last row.
Yes, sorting determines which row is considered the last row.
Yes, it is evaluated after aggregation and depends on the view layout.
Yes, it is commonly used to filter or highlight ending rows.