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()

ParameterTypeDescription
NoneN/ALAST() 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 0

  • Rows 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 0 for the last row in a partition

    • Returns positive integers (1, 2, 3, …) for rows before the last

Example Output

Row PositionLAST()
1st3
2nd2
3rd1
Last0

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 calculations

  • LAST() values change if sort order changes

  • Not 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.

1. What does LAST() return in Tableau?

It returns the number of rows between the current row and the last row in a partition.

2. Why does LAST() return positive numbers?

Rows before the last row are counted as positive offsets relative to the last row.

3. Is LAST() affected by sorting?

Yes, sorting determines which row is considered the last row.

4. Is LAST() a table calculation?

Yes, it is evaluated after aggregation and depends on the view layout.

5. Can LAST() be used as a filter?

Yes, it is commonly used to filter or highlight ending rows.