Site icon i2tutorials

Amazon QuickSight – Lag

Amazon QuickSight – Lag

 

The Amazon QuickSight “lag” function is a table calculation function that allows you to compute the difference between a measure or dimension value in the current row and a value in a previous row.

 

Syntax

#Start#
lag(
     measure or dimension field 
     ,[ sortorder_field ASC_or_DESC, ... ]  
     ,lookup_index,
     ,[ partition_field, ... ] 
)
#End#

 

This function takes the following arguments:

 

 

Here’s an example of the “lag” function in action:

 

Suppose you have a dataset that contains sales data for a store, and you want to calculate the difference between the current day’s sales and the previous day’s sales. You can use the “lag” function to achieve this.

 

Assume that the dataset has the following fields: “Date” (dimension), “Sales” (measure).

 

The following formula will calculate the difference between the current day’s sales and the previous day’s sales:

 

Example

#Start#
lag(Sales, 1, [Date])
#End#

 

This formula looks up the sales value for the previous date (using lookup_index set to 1) and partitions the data by the “Date” field.

 

Exit mobile version