> ## Documentation Index
> Fetch the complete documentation index at: https://honeydew.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Are customers spending more per visit?

> Pin a metric to a fixed grain, then aggregate over it to get correct averages at any slice

## When would you use this?

* A menu designer asks *"Which trucks have customers spending the most per visit?"* -
  requires averaging total order spend, not individual line-item prices.
* Finance wants to track average order value over time to measure whether upselling
  campaigns are working, sliced by city and truck.
* Operations needs to identify *premium* trucks - those where more than half of orders
  exceed \$50 - to decide which locations to prioritize for higher-end menu items.
* You need an AOV metric that works correctly whether a BI user groups by truck, city,
  day, or customer age group - without duplicating logic for each view.

## What this recipe builds

Two metrics demonstrating the **fixed-grouping pattern**. The inner
metric uses `GROUP BY (order_header.order_id)` to always compute at
order grain - the grain never changes regardless of user context.
The outer metric averages that fixed-grain value, inheriting
whatever dimension the user has chosen. The result: AOV is always
computed correctly at order grain, regardless of how the data is
sliced.

<Tip>
  This recipe uses the [fixed grouping](/docs/calculations/metrics#fixed-grouping)
  concept. See the documentation for the full technical reference.
</Tip>

## Steps

<Steps>
  <Step title="Revenue per order (inner)">
    Total revenue per order - always at order grain regardless of user
    context. The fixed `GROUP BY` never changes.

    Since it is defined as a metric, it responds to user-applied
    filters. For example, filtering to a single city computes
    revenue per order for that city only.

    <Tabs>
      <Tab title="SQL">
        ```sql theme={null}
        SUM(order_detail.price) GROUP BY (order_header.order_id)
        ```
      </Tab>

      <Tab title="YAML">
        ```yaml theme={null}
        type: metric
        entity: order_detail
        name: order_total_revenue
        display_name: Revenue per order (inner)
        description: |-
          Total revenue summed to order grain - always grouped by
          order_id regardless of user context.
        datatype: float
        sql: |-
          SUM(order_detail.price) GROUP BY (order_header.order_id)
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Average Order Value">
    Mean spend per order visit. Grouped by truck = AOV per truck.
    Grouped by city = AOV per city. Always correct because the inner
    grain is fixed.

    <Tabs>
      <Tab title="SQL">
        ```sql theme={null}
        AVG(order_detail.order_total_revenue)
        ```
      </Tab>

      <Tab title="YAML">
        ```yaml theme={null}
        type: metric
        entity: order_detail
        name: avg_order_value
        display_name: Average Order Value (AOV)
        description: |-
          Average revenue per order, dynamic to any user grouping.
          Inner metric fixes grain at order_id. Outer AVG collapses
          to user context.
        datatype: float
        sql: |-
          AVG(order_detail.order_total_revenue)
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

### Example - sliced by country

| Country    | AOV         |
| ---------- | ----------- |
| India      | \$43.00     |
| Germany    | \$42.02     |
| Sweden     | \$41.99     |
| England    | \$41.97     |
| Australia  | \$41.49     |
| **Global** | **\$40.74** |

Each row shows the average order value for that country. The
inner metric computes revenue per order, and the outer `AVG`
collapses to the country level. The global AOV (\$40.74) is the
average order value across all orders.

## Next step

To compute what fraction of orders exceed a threshold using the
fixed-grain metric, see
[High value order share](/docs/recipes/high-value-order-share).

## Related reading

* [Fixed grouping](/docs/calculations/metrics#fixed-grouping) -
  reference on `GROUP BY (entity.key)`
