Wednesday, June 28, 2023

Explain the Table Calculation Function ' FIRST ' in Tableau with Example?

 In Tableau, the FIRST function is a table calculation function that allows you to retrieve the first value of a dimension or measure within a specified context or partition. The FIRST function is typically used to analyze or compare the initial value in a sorted order.

The syntax for the FIRST function in Tableau is as follows:

FIRST(expression, [start], [end])

  • expression: The field or calculation for which you want to retrieve the first value.
  • start (optional): Specifies the starting point of the partition or order. If not specified, the partition starts from the first row in the partition.
  • end (optional): Specifies the ending point of the partition or order. If not specified, the partition ends at the current row.

Here's an example to demonstrate how to use the FIRST function in Tableau:

Suppose you have a dataset that contains information about monthly sales for different regions. You want to retrieve the first month's sales for each region to analyze the initial performance.

  1. Open Tableau and connect to your dataset.
  2. Drag the "Region" field to the Rows shelf to create a table view with regions.
  3. Drag the "Month" field to the Columns shelf to display months horizontally.
  4. Drag the "Sales" field to the Marks card to apply the aggregation. By default, Tableau will aggregate the sales using the SUM function.
  5. Right-click on the "Sales" field in the Marks card and select "Add Table Calculation."
  6. In the calculation dialog box, choose "FIRST" from the list of table calculation functions.
  7. Configure the specific settings for the FIRST function, such as the addressing and partitioning options.
  8. Click "OK" to apply the FIRST function to the sales values.


Tableau will display the first month's sales for each region based on the applied table calculation. You can further customize the view, apply sorting, or add additional calculations based on the first value.

The FIRST function is useful when you want to analyze or compare the initial value within a specific context, such as the first value in a sorted order, the first value within a partition, or the first value based on a specific condition.

By leveraging the FIRST function in Tableau, you can gain insights into the initial performance or occurrence of a dimension or measure within your dataset.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...