How can I accurately retrieve a customer's most recent order in Shopify Flow?

Topic summary

Goal: Retrieve the customer’s previous (most recent prior) order in a Shopify Flow triggered by a new order.

Observed issues:

  • customer.lastOrder (e.g., order.customer.lastOrder.shippingAddress.address1) returns the customer’s first order, not the most recent, per the user’s testing.
  • “Get order data” search (customer_id:{{order.customer.legacyResourceId}} AND created_at:>=‘{{ “now” | date_minus:“1 day” }}’) returns recent orders but includes the order that triggered the flow, so a single result is the current order, not the prior one.

Attempts and limitations:

  • Fetching the last 2 orders doesn’t help because the user can’t skip or ignore the first returned item within Flow.
  • Tried adjusting the time window (e.g., changing “now” to something like “1 hour”) to exclude the just-created order; this did not work as intended.

Technical context:

  • Shopify Flow filters/search use created_at and Liquid date filters (date_minus). legacyResourceId identifies the customer.

Status: Unresolved. The user seeks a method to either exclude the triggering order from results or directly select the previous order.

Summarized with AI on January 15. AI used: gpt-5.
  • order.customer.lastOrder.shippingAddress.address1 is not returning the last order but rather the customer’s first order
  • Get order data (customer_id:{{order.customer.legacyResourceId}} AND created_at:>=‘{{ “now” | date_minus:“1 day” }}’) returns the last X orders, but it includes the order that triggered the flow. This means if 1 order is returned it will be the order that triggered the flow and not the previous order.

If customer.lastOrder doesn’t return the last order, and a get order data query includes the order that triggered the flow, how do I get the customer’s previous order?

I have tried getting the last 2 orders from a get order data query, but I don’t know how to skip the first entry, and I have tried editing the query to change “now” to something like “1 hour” but it doesn’t work. Here is the query:

customer_id:{{order.customer.legacyResourceId}} AND created_at:>=‘{{ “now” | date_minus:“1 day” }}’

If I can get the query to return results that skip the last few minutes up to X days, it should work.