# Date breakdown

To perform a date breakdown query on the cart resource send a `POST` request to the `/carts/date_breakdown` endpoint specifying in the payload the [query keys](#query-keys) and [filter](/metrics-api-reference/resources/carts/filters.md) parameters like in the generic example below:

```json
{
  "date_breakdown": {
    "by": "...",
    "field": "...",
    "operator": "...",
    "interval": "...",
    "breakdown": {
      "by": "...",
      "field": "...",
      "operator": "...",
      "condition": { ... },
      "sort": "...",
      "limit": ...,
      "breakdown": {
        "by": "...",
        "field": "...",
        "operator": "...",
        "condition": { ... },
        "sort": "...",
        "limit": ...
      }
    }
  },
  "filter": { ... }
}
```

{% hint style="info" %}
Please find more information on how date breakdown queries work [here](/metrics/getting-started/queries/date-breakdown.md).
{% endhint %}

### Query keys

These are the keys you need to set when performing a date breakdown query:

<table><thead><tr><th>Key</th><th>Type</th><th data-type="checkbox">Required</th><th>Description</th><th>Values</th></tr></thead><tbody><tr><td><strong><code>by</code></strong></td><td>String</td><td>true</td><td>The date field you want the results of the query aggragated by.</td><td>See the <a href="#by-values">related table</a> to check the full list of valid values for this key.</td></tr><tr><td><strong><code>field</code></strong></td><td>String</td><td>true</td><td>The field you want the metrics or statistics computed on.</td><td>See the <a href="#operators-and-field-values">related table</a> to check the full list of valid values for this key.</td></tr><tr><td><strong><code>operator</code></strong></td><td>String</td><td>true</td><td>The computing operator.</td><td>See the <a href="#operators-and-field-values">related table</a> to check the full list of valid operators based on the value you assigned to the <code>field</code> key.</td></tr><tr><td><strong><code>interval</code></strong></td><td>String</td><td>false</td><td>The time interval over which the metrics / stats are computed. The results will be aggregated by date accordingly.</td><td>One of <code>hour</code>, <code>day</code>, <code>week</code>, <code>month</code>, or <code>year</code> (default is <code>month</code>).</td></tr><tr><td><strong><code>breakdown</code></strong></td><td>Object</td><td>false</td><td>The optional breakdown (eventually nested).</td><td>See the <a href="/pages/4PMkKyoNosKF6AYrXQeT">related section</a> for any information about the breakdown query.</td></tr></tbody></table>

### `by` values

These are the valid values you can specify for the `by` key of the date breakdown query:

| Value                            | Description                                                                                                                                                                                                          |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`order.created_at`**           | The date and time at which the order was created (complete date plus hours, minutes and seconds — according to the [ISO 8601](https://www.w3.org/TR/NOTE-datetime) standard).                                        |
| **`order.updated_at`**           | The date and time at which the order was last updated (complete date plus hours, minutes and seconds — according to the [ISO 8601](https://www.w3.org/TR/NOTE-datetime) standard).                                   |
| **`order.current_date`**         | The date and time of the order's latest status change, regardless of the order's status (complete date plus hours, minutes and seconds — according to the [ISO 8601](https://www.w3.org/TR/NOTE-datetime) standard). |
| **`resource_errors.created_at`** | The date and time at which the resource error was created (complete date plus hours, minutes and seconds — according to the [ISO 8601](https://www.w3.org/TR/NOTE-datetime) standard).                               |
| **`resource_errors.updated_at`** | The date and time at which the resource error was updated (complete date plus hours, minutes and seconds — according to the [ISO 8601](https://www.w3.org/TR/NOTE-datetime) standard).                               |

### Operators and `field` values

These are the valid values you can specify for the `field` key of the date breakdown query and the related valid operators, based on that key:

| Value                                     | Operators                                                                                                             |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| **`customer.id`**                         | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`customer.email`**                      | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`customer.group_name`**                 | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`customer.reference`**                  | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`customer.reference_origin`**           | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`line_items.code`**                     | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`line_items.discount`**                 | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.id`**                       | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`line_items.item_id`**                  | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`line_items.options_amount`**           | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.quantity`**                 | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.tax_amount`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.tax_rate`**                 | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.total_amount`**             | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.unit_amount`**              | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.options.id`**               | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`line_items.options.quantity`**         | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.options.total_amount`**     | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`line_items.options.unit_amount`**      | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`market.id`**                           | `cardinality`                                                                                                         |
| **`market.number`**                       | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`order.adjustment_amount`**             | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.adjustment_tax_amount`**         | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.adjustment_taxable_amount`**     | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.discount_amount`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.duty_amount`**                   | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.gift_card_code`**                | `value_count`                                                                                                         |
| **`order.gift_card_amount`**              | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.id`**                            | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`order.line_item_options_count`**       | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.number`**                        | `value_count`                                                                                                         |
| **`order.payment_method_amount`**         | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.payment_method_tax_amount`**     | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.payment_method_taxable_amount`** | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.reference`**                     | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`order.reference_origin`**              | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`order.shipments_count`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.shipping_amount`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.shipping_taxable_amount`**       | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.skus_count`**                    | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.subtotal_amount`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.subtotal_tax_amount`**           | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.subtotal_taxable_amount`**       | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.total_amount`**                  | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.total_amount_with_taxes`**       | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.total_tax_amount`**              | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`order.total_taxable_amount`**          | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`resource_errors.code`**                | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`resource_errors.id`**                  | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`resource_errors.message`**             | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.commercelayer.io/metrics-api-reference/resources/carts/date-breakdown.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
