# Is there a way to add a filter to query data between two dates?

**URL:** <https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402>\
**Category:** Ask the Community\
**Created:** [February 3, 2023, 10:35pm UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402 "2023-02-03T22:35:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SterlingParamoreMSE](https://community.holistics.io/user_avatar/community.holistics.io/sterlingparamoremse/32/689_2.png) [@SterlingParamoreMSE](https://community.holistics.io/u/SterlingParamoreMSE)\
**Post date:** [February 3, 2023, 10:35pm UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/1 "2023-02-03T22:35:08Z")

</div>

I have a data model with records that have two dates: `valid_from` and `valid_to`. I would like to create a Holistics report with a date filter that would show all records where the selected date is between `valid_from` and `valid_to`. It’s not obvious to me if this is this possible with Holistics?

---

<div class="post-metadata">

**Author:** ![huy](https://community.holistics.io/user_avatar/community.holistics.io/huy/32/390_2.png) [@huy](https://community.holistics.io/u/huy)\
**Post date:** [February 4, 2023, 1:22am UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/2 "2023-02-04T01:22:34Z")

</div>

Hi Sterling, if it’s about letting users choose the 2 dates, then this is supported natively using our Date filter.

![filter date between 2 dates](https://community.holistics.io/uploads/default/original/2X/6/69741c98916e1ac848b08ced0b7180d4f029bd22.gif)

Or are you talking about pre-setting the date filters to pull values from these 2 fields in your data model? How do you imagine it to work?

---

<div class="post-metadata">

**Author:** ![SterlingParamoreMSE](https://community.holistics.io/user_avatar/community.holistics.io/sterlingparamoremse/32/689_2.png) [@SterlingParamoreMSE](https://community.holistics.io/u/SterlingParamoreMSE)\
**Post date:** [February 4, 2023, 1:27am UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/3 "2023-02-04T01:27:36Z")

</div>

I have data that looks like this:

| attribute | valid\_from | valid\_to |
| --- | --- | --- |
| A | 2023-01-05 | 2023-01-31 |
| B | 2023-01-22 | 2023-02-05 |
| C | 2023-01-22 | 2023-06-22 |

I want to see all records that were valid at a given time specified by a filter. So if I wanted to see all records that were valid on `2023-02-04`, I would see records `B` and `C`.

---

<div class="post-metadata">

**Author:** ![huy](https://community.holistics.io/user_avatar/community.holistics.io/huy/32/390_2.png) [@huy](https://community.holistics.io/u/huy)\
**Post date:** [February 4, 2023, 1:53am UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/4 "2023-02-04T01:53:54Z")

</div>

I see. That’s an interesting one. Basically adding this where condition to the report:

```auto
    WHERE valid_from >= ${date_d}
        AND valid_to <= ${$date_d}

```

I need to check internally, but I think our upcoming [Dynamic Models](https://community2.holistics.io/t/upcoming-launch-dynamic-models-aka-query-parameters/1341) might be the solution here.

We can build a dynamic model like this, and use it to create the final report.

```javascript
Model attributes_with_filter (date_d: Date) {
  type: 'query'
  
  query: @sql
    SELECT * from {{attributes}}
    WHERE valid_from >= ${date_d}
        AND valid_to <= ${$date_d}
  ;;

  dimension...
}
```

---

<div class="post-metadata">

**Author:** ![SterlingParamoreMSE](https://community.holistics.io/user_avatar/community.holistics.io/sterlingparamoremse/32/689_2.png) [@SterlingParamoreMSE](https://community.holistics.io/u/SterlingParamoreMSE)\
**Post date:** [February 4, 2023, 2:06am UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/5 "2023-02-04T02:06:19Z")

</div>

Exactly! I’m really excited about these dynamic models.

---

<div class="post-metadata">

**Author:** ![Khai\_To](https://community.holistics.io/user_avatar/community.holistics.io/khai_to/32/128_2.png) [@Khai\_To](https://community.holistics.io/u/Khai_To)\
**Post date:** [February 6, 2023, 8:22am UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/6 "2023-02-06T08:22:19Z")

</div>

Hi @SterlingParamoreMSE,  
Could you also check this [Holistics Guide](https://docs.holistics.io/guides/point-in-time-report) for a workaround?  
You can consider create a single date dimension from your `valid_from` and `valid_to`.

---

<div class="post-metadata">

**Author:** ![SterlingParamoreMSE](https://community.holistics.io/user_avatar/community.holistics.io/sterlingparamoremse/32/689_2.png) [@SterlingParamoreMSE](https://community.holistics.io/u/SterlingParamoreMSE)\
**Post date:** [February 6, 2023, 4:29pm UTC](https://community.holistics.io/t/is-there-a-way-to-add-a-filter-to-query-data-between-two-dates/1402/7 "2023-02-06T16:29:07Z")

</div>

I’d considered something like that, but was concerned about the table getting too large if we expanded every date range into rows like that. Haven’t tested it out yet to see how bad it might be.
