How to calculate customers last 12 Month sales amount

How to calculate customers last 12 Month sales amount

floriangoerig
Tourist
20 0 1

Hi there,

 

I want to calculate 12-months-sales-amount and 12-month-order-count and write it to the corresponding customer metafields. Based on that calculation I want to add customer classification tags based on a fixed rule-set.

 

Trigger clearly is the order created. But what then?

What Action to take? How to query and set variables and then write these variables into metafield values?

 

Thankful for any hints on that.

🤙

 

 

Reply 1 (1)

RPiii
Shopify Staff
137 24 39

There are a few fields on the Customer object that may help you achieve your goals here:

  • amountSpent is the total amount that the customer has spent on orders in their lifetime.
  • lifetimeDuration is the amount of time since the customer was first added to the store.
  • numberOfOrders is the number of orders that the customer has made at the store in their lifetime.

Otherwise, you might be able to calculate the rolling 12-month amount spent and number of orders by using a Get order data action with a query limited to the specific customer and date range and then a Run code action to calculate the resulting values to include in the Update customer metafield action.