Tableau Funtion: FIRST( )

Tableau Function: FIRST()

Category: Table Calculation Functions

Purpose

The FIRST() function in Tableau is a table calculation that returns the relative position of the first row (or mark) in a partition. It is primarily used to determine ordering and positional logic within a defined window of data.

In simple terms, FIRST() tells you how far the current row is from the first row in the partition.

Type of Calculations

  • Table calculations

  • Index-based positional calculations

  • Relative row positioning

  • Order-dependent calculations

Unlike row-level or aggregate functions, FIRST() operates after aggregation, based on how data is displayed in the view.

Practical Use Cases

  • Identifying the first record in a sorted list

  • Creating rank-based filters

  • Calculating running comparisons against the first value

  • Building custom index or offset calculations

  • Highlighting or labeling the starting point of a partition


FIRST()

ParameterTypeDescription
NoneN/AFIRST() does not require or accept any parameters. Its output depends entirely on the table calculation scope and sort order.

How It Works?

Logical Principle

FIRST() calculates the offset distance from the first row in a partition:

FIRST() = Current Row Index − First Row Index

Because Tableau counts forward rows as negative offsets:

  • The first row is always 0

  • Every row after moves backward numerically

Partition Dependency

The result depends on:

  • Partitioning (Compute Using)

  • Sorting order

  • Table calculation direction (Table Down, Pane Across, etc.)

What Does It Return?

    • Data Type: Integer

    • Meaning:

      • Returns 0 for the first row in the partition

      • Returns negative integers (-1, -2, -3, …) for subsequent rows

    Example Output

    Row PositionFIRST()
    1st0
    2nd-1
    3rd-2

When Should We Use It?

Use FIRST() when you need to:

  • Identify or isolate the first value in a sorted dataset

  • Compare values relative to the starting point

  • Create custom filters (e.g., show first N rows)

  • Build offset-based metrics

  • Control row-aware logic in dashboards

Basic Usage

Identify the first row only


FIRST() = 0

  • Returns TRUE only for the first row
  • Useful for conditional formatting or labels

Column Usage

Create a calculated field to label the first record


IF FIRST() = 0 THEN "First Record" ELSE "Other" END

  • Labels the first mark in each partition
  • Common in ranked or sorted views

Advanced Usage

Compare current value to the first value


SUM([Sales]) - LOOKUP(SUM([Sales]), FIRST())

  • Calculates the difference between each row’s sales and the first row
  • Common in trend and variance analysis

Tips and Tricks

  • Always check the table calculation direction

  • Sorting directly affects FIRST() results

  • Use Compute Using carefully to control partitions

  • FIRST() does not work without a defined view

  • Avoid using it in row-level logic

Related Functions You Might Need

Functions commonly used with or as alternatives to FIRST():

  • LAST()

  • INDEX()

  • LOOKUP()

  • RANK()

  • RUNNING_SUM()

  • WINDOW_MIN()

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 FIRST() return in Tableau?

It returns an integer offset showing how far the current row is from the first row in the partition.

2. Why does FIRST() return negative numbers?

Tableau counts forward rows as negative offsets relative to the first row.

3. Is FIRST() an aggregate function?

No. It is a table calculation evaluated after aggregation.

4. Does FIRST() depend on sorting?

Yes. Sorting directly determines which row is considered “first.”

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

Yes, it is commonly used to filter Top-N rows or isolate the first record.