# \[LOD\] Comparing metrics to a custom time range

**URL:** <https://community.omni.co/t/lod-comparing-metrics-to-a-custom-time-range/422>\
**Category:** Modeling\
**Tags:** lod\
**Created:** [November 13, 2025, 12:57am UTC](https://community.omni.co/t/lod-comparing-metrics-to-a-custom-time-range/422 "2025-11-13T00:57:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrienb](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/adrienb/32/385_2.png) [@adrienb](https://community.omni.co/u/adrienb)\
**Post date:** [November 13, 2025, 12:57am UTC](https://community.omni.co/t/lod-comparing-metrics-to-a-custom-time-range/422/1 "2025-11-13T00:57:01Z")

</div>

This Level-of-Detail example walks through creating the following analysis, where a user-selected time period serves as the benchmark against which to compare a different time period. For example, in this screenshot we can see both the average during the 12 to 9 month-ago period, as well as how sales have compared to that average across the entire time frame.

 ![image](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/07035d8d012eafd3094865470cd168940e12b9c8.png)

Here is how to build this:

1. Select the base metrics you need, in this case the `Created At Date` and `Total Sale Price`.
2. Create a filter-only field to be used as the user selection - here I called it `Period Reference`

```yaml
filters:
  period_reference:
    type: timestamp

```

1. Create a next metric for `Sale Price in Reference Period` that returns only the sale price when the query dates are within the selected period.

```yaml
sale_price_in_reference_period:
    sql: |
      CASE WHEN ${monthly_total_price.created_at_month[date]} >= {{filters.monthly_total_price.period_reference.range_start}} 
      AND ${monthly_total_price.created_at_month[date]} <= {{filters.monthly_total_price.period_reference.range_end}} 
      THEN ${monthly_total_price.total_sale_price}
      ELSE NULL END
    label: Sale Price in Reference Period
    format: USDCURRENCY_2

```

1. Use this field to create a level of detail field that averages `Sale Price in Reference Period`.  

2. We now have the necessary fields to build the first chart, using the `Total Sale Price` as the area chart, the LOD field as the average line, and the `Sale Price in Reference Period` as the overlayed red area. 

3. To build the second chart, duplicate the tab and calculate a simple percent difference calculation. This can be done using Excel as below, or via the `+Add Field` button and the drag and drop SQL box.

4. Finally, plot this `% Diff to Period Avg` against the date field. When saving this to a dashboard, make sure to add the `Period Reference` as a dashboard-level filter, and you’re done!
