While analyzing the sales pattern, it is important to identify the repeated customers and determine their recent orders. This article shows how to use this Tableau LAST function to find the recent order date by a product, category, Subcategory, or customer name with examples.
Tableau LAST function
The Tableau LAST function is helpful to find the last record or row in a table, pane, etc. If you use it on the whole table, it returns the numeric value from n to 0, where 0 is the last record and n is the first record. However, if you use the assignment operator, it will return a boolean True or False.
The syntax of the Tableau LAST function is as shown below.
To demonstrate the Tableau LAST function to find the recent order date by a customer or product, we use the Sample Superstore. Drag and drop the Sales to the Columns Shelf and the Customer Name and Order Date to the Rows shelf.
Tableau LAST function to find the recent order date
Please change the Year of Order Date to Extract date and change it from Continuous to Discrete. If the default Mark type shows the Line Chart. Please change the Marks type to Bar Chart. For the remaining charts in Tableau, please click here.
First, we must create a calculated Field to use the built-in LAST function. Use the Analysis Menu and select the Create Calculated Field.. option to do this. Please refer to the Table Functions, other Functions, and Excel Source articles.
Let me rename it as the Last Order and write the below expression. It will return True if it is the last row of the section. In this case, it returns True if it is the last row of each customer.
LAST() = 0
Drag the newly created calculate field to the Rows shelf. By default, it will perform the Table(down) calculation. So, the Tableau LAST function returns True for the last customer record in the whole table by order date. Next, click the Down arrow beside the Last Order and click the Edit Table Calculation option.
Please change the Compute using from Table(down) to Specific Dimension and checkmark the fields. Remember, the Fields must be in the same order. Next, select Customer Name as the Restarting every option. Once. You change them, and you can see the True for the last row of every customer, i.e., the customer’s last or latest order.
Use the control or command button to select the last order calculated field in the Rows Shelf and drag it to the Filters Shelf. By default, the window below will appear. Choose True and click OK. It means it will show the Customer’s last orders.
The Tableau LAST function screenshot below finds and shows the recent or the latest customer order date.
Let me find out the latest order placed by the product subcategory. To do so, remove the Customer Name from the Rows Shelf and the Last Order from the Filters Shelf. Next, add a Subcategory to the Rows Shelf.
Click the down arrow beside the Last Order, choose the Edit Table Calculation, and choose the Subcategory.
Next, drag the Last order from the Rows shelf to the Filters shelf to remove the True/False column. Next, add a Subcategory to the Color shelf and add colors to the bar chart. The below Tableau LAST function image shows the latest or recent orders from the product subcategory based on the order date.