KNOWLEDGE BASE

Displaying Only First or Last Value in a Partition


Published: 18 Feb 2014
Last Modified Date: 16 Jan 2017

Question

How to display only the first or last value in a partition.

Environment

Tableau Desktop

Answer

To Show Only the Last Value in a Partition

  1. In Tableau Desktop, connect to Sample Superstore data.
  2. Drag Order Date to Columns and Sales to Text.
  3. select Analysis > Create Calculated Field.
  4. In the Calculated Field dialog box that opens, type a name for the field. The attached example workbook uses Last.
  5. In the formula field, type the following, and then click OK:
    IF LAST() = 0 THEN SUM([Sales]) END
  6. Drag SUM(Sales) off the Marks card and then drag the newly created calculated field to Text.

To Show Only the First Value in a Partition

  1. In Tableau Desktop, connect to Sample Superstore data.
  2. Drag Order Date to Columns and Sales to Text.
  3. select Analysis > Create Calculated Field.
  4. In the Calculated Field dialog box that opens, type a name for the field. The attached example workbook uses First.
  5. In the formula field, type the following, and then click OK:
    IF FIRST() = 0 THEN SUM([Sales]) END
  6. Drag SUM(Sales) off the Marks card and then drag the newly created calculated field to Text.
To view these steps in action, see the video below: 

 

Additional Information

The LAST() function returns the number of rows from the current row to the last row in the partition. The last row in a partition will return a 0.
Did this article resolve the issue?