> ## 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.

# What fraction of orders exceed a revenue threshold?

> Share of orders above a threshold, using either a fixed amount or a data-driven percentile

## Prerequisite

This recipe builds on the fixed-grain `order_total_revenue` metric
from [Average order value](/docs/recipes/avg-order-value). Complete that
recipe first.

## When would you use this?

* 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.
* A product manager asks *"What share of orders are high-value?"*
  and you need a metric that works across any grouping dimension.
* You want a threshold that adapts to the data distribution
  rather than a hard-coded dollar amount.

## What this recipe builds

A ratio metric that counts orders above a threshold and divides
by total orders. The threshold is evaluated at order grain using
the fixed-grain inner metric (`order_total_revenue`), then the
share is computed at user context.

The recipe shows two approaches to defining the threshold:

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

## Use case 1 - Fixed dollar threshold

A hard-coded threshold, that answers: *"What percentage of orders exceed 50 dollars"*

Use this when the business has a specific dollar cutoff that
defines "high value" - for example, a promotion tier or a
pricing benchmark.

<Tabs>
  <Tab title="SQL">
    ```sql theme={null}
    COUNT(DISTINCT order_header.order_id)
    FILTER (WHERE order_detail.order_total_revenue > 50)
    / NULLIF(COUNT(DISTINCT order_header.order_id), 0)
    ```
  </Tab>

  <Tab title="YAML">
    ```yaml theme={null}
    type: metric
    entity: order_detail
    name: high_value_order_share
    display_name: High Value Order Share
    description: |-
      Share of orders where total order revenue exceeds $50.
      FILTER applied on top of a fixed-grain metric: the threshold
      is evaluated per order, then the share is computed at user
      context.
    datatype: float
    sql: |-
      COUNT(DISTINCT order_header.order_id)
      FILTER (WHERE order_detail.order_total_revenue > 50)
      / NULLIF(COUNT(DISTINCT order_header.order_id), 0)
    ```
  </Tab>
</Tabs>

### Example - sliced by country

Seoul 2022, top trucks by AOV:

| Truck | AOV     | High-value order share |
| ----- | ------- | ---------------------- |
| 260   | \$60.46 | 56.1%                  |
| 269   | \$58.38 | 50.4%                  |
| 267   | \$50.63 | 42.9%                  |
| 257   | \$44.93 | 36.6%                  |
| 266   | \$44.90 | 37.7%                  |

Trucks 260 and 269 have more than half their orders above \$50,
making them candidates for premium menu expansion.

## Use case 2 - Percentile-based threshold

A data-driven threshold that adapts to the distribution. Instead
of a fixed dollar amount, the cutoff is the 75th percentile of
order revenue. The share answers: *"What percentage of orders
fall in the top quartile?"*

Use this when there is no natural dollar cutoff, or when you
want the definition of "high value" to move with the data over
time.

<Steps>
  <Step title="75th percentile of order revenue">
    The global 75th percentile, computed with `group by ()` so it
    stays the same regardless of user grouping. Filters still
    apply - filtering to a single country gives that country's
    75th percentile.

    <Tabs>
      <Tab title="SQL">
        ```sql theme={null}
        PERCENTILE_CONT(0.75) WITHIN GROUP
        (ORDER BY order_detail.order_total_revenue) group by ()
        ```
      </Tab>

      <Tab title="YAML">
        ```yaml theme={null}
        type: metric
        entity: order_detail
        name: p75_order_revenue
        display_name: 75th Percentile Order Revenue
        description: |-
          The 75th percentile of order total revenue.
          Uses group by () so the value is always the global percentile,
          unaffected by user grouping dimensions.
        datatype: float
        sql: |-
          PERCENTILE_CONT(0.75)
            WITHIN GROUP (ORDER BY order_detail.order_total_revenue) group by ()
        ```
      </Tab>
    </Tabs>

    The current global value is **\$57.00**.
  </Step>

  <Step title="Top quartile order share">
    Orders above the 75th percentile as a share of all orders. The
    `FILTER` clause references `p75_order_revenue` - the percentile
    metric from the previous step - so the threshold adapts as the
    data distribution changes.

    <Tabs>
      <Tab title="SQL">
        ```sql theme={null}
        COUNT(DISTINCT order_header.order_id)
        FILTER (WHERE order_detail.order_total_revenue
          > order_detail.p75_order_revenue)
        / NULLIF(COUNT(DISTINCT order_header.order_id), 0)
        ```
      </Tab>

      <Tab title="YAML">
        ```yaml theme={null}
        type: metric
        entity: order_detail
        name: top_quartile_order_share
        display_name: Top Quartile Order Share
        description: |-
          Share of orders where total order revenue exceeds the 75th
          percentile. The threshold adapts to the data distribution
          rather than using a hard-coded value.
        datatype: float
        sql: |-
          COUNT(DISTINCT order_header.order_id)
          FILTER (WHERE order_detail.order_total_revenue
            > order_detail.p75_order_revenue)
          / NULLIF(COUNT(DISTINCT order_header.order_id), 0)
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

### Example

The global top quartile share is approximately **24.8%** -
close to the expected 25% for a 75th-percentile cutoff. The
small deviation comes from orders that land exactly on the
percentile boundary.

## How the two behave differently

| Aspect               | Fixed threshold (\$50)             | Percentile (p75)                         |
| -------------------- | ---------------------------------- | ---------------------------------------- |
| Cutoff value         | Always \$50                        | Currently \$57, adapts over time         |
| Share when AOV rises | Increases - more orders cross \$50 | Stays near 25% by definition             |
| Best for             | Business rules, promotion tiers    | Distribution analysis, outlier detection |

## Key design notes

| Concern                           | Guidance                                                                                                                                                                              |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Threshold on a fixed-grain metric | Both use cases reference `order_total_revenue`, which uses a fixed `GROUP BY (order_header.order_id)`. Without fixed grouping, the threshold would apply to line-item prices instead. |
| `group by ()` on the percentile   | The percentile metric uses `group by ()` so it computes the global percentile. Without it, the percentile would shift per slice, defeating the purpose of a stable cutoff.            |
| Ratio structure                   | Both metrics divide filtered count by total count. `NULLIF` prevents division by zero when a slice has no orders.                                                                     |

## Related reading

* [Average order value](/docs/recipes/avg-order-value) -
  prerequisite recipe
* [Filters](/docs/calculations/filters) -
  reference on `FILTER (WHERE ...)`
* [Ratio metrics](/docs/calculations/metrics#filtered-metrics-in-ratios) -
  using filtered metrics inside ratio expressions
* [Fixed empty grouping](/docs/calculations/metrics#fixed-empty-grouping) -
  locking the percentile with `group by ()`
