Compare order value vs that customer's previous order

Topic summary

A merchant wants to create a Shopify Flow workflow that triggers when a customer places their 2nd or 3rd order, comparing the order value against their previous order. The goal is to identify when a second order falls below a threshold (e.g., $728) after a first order exceeded it, enabling targeted follow-up promotions.

Key Challenge:
The user struggled with using the “Get order data” action to retrieve and compare the last two orders’ subtotals.

Solution Provided:

  • Sort orders by “Created at” in descending order to get the most recent orders first
  • Use query filter “Placed by same customer in last day” (removing the date constraint)
  • Since Flow conditions cannot directly compare two list items, use the “Run code” action
  • The code checks if customer has 2+ orders, parses subtotals of current and previous orders, then returns a boolean “followUp” value
  • A subsequent condition step checks if followUp is true to trigger actions

Important Note:
The Customer.numberOfOrders property has a 1-2 hour delay in updating, so that check was removed from the workflow.

Outcome:
Complete working code examples were provided for both scenarios: any order after the first, and specifically for 2nd/3rd orders only.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

Hi Wilkius,

To get the last two orders, you should use Sort data by “Created at” in Descending order. Sorting in descending order ensures that the most recent orders are at the top of the list. Once sorted, you can then retrieve the first two orders from this sorted list.

Here is an example of orders being sorted by “Created at” in Descending order and Ascending order in the Shopify dashboard

Here’s a screenshot that explains the properties “Created at” and “Processed at”

Reference: https://shopify.dev/docs/api/admin-rest/2024-07/resources/order#resource-object