# How to Restrict Particular Metric with custom date Filter

**URL:** <https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822>\
**Category:** Q&A\
**Tags:** filters, calculations, quick-sight\
**Created:** [February 8, 2023, 1:28pm UTC](https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822 "2023-02-08T13:28:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpradeepkumar](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@bpradeepkumar](https://community.amazonquick.com/u/bpradeepkumar)\
**Post date:** [February 8, 2023, 1:28pm UTC](https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822/1 "2023-02-08T13:28:53Z")

</div>

I have created the custom date filter like, last 1 year, last 2 years, last 5 years and current month.

i have created calculated field like  
sum(ifelse(Date field \> addDateTime(-12,‘MM’,${date}) AND Date field \<= ${date} AND {metric\_desc}=‘Occupancy’,value1,NULL)) /  
sum(ifelse(Date field \> addDateTime(-12,‘MM’,${date}) AND Date field \<= ${date} AND {metric\_desc}=‘Occupancy’,value2,NULL))

in metric\_desc we have like

![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/6/647015afc961a283142c6e23219254b33b4322d0.png)

In this i am trying to get the data for last 12 months restricing the data only to Occupancy, when i am trying to do using the above calculation not able to get any data.  
Please help me out to solve the above issue.

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [February 8, 2023, 5:17pm UTC](https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822/2 "2023-02-08T17:17:06Z")

</div>

Instead of NULL can you try 0

---

<div class="post-metadata">

**Author:** ![bpradeepkumar](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@bpradeepkumar](https://community.amazonquick.com/u/bpradeepkumar)\
**Post date:** [February 8, 2023, 5:27pm UTC](https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822/3 "2023-02-08T17:27:55Z")

</div>

tried with 0 but output is no value where is some value in our report

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [March 7, 2023, 4:49pm UTC](https://community.amazonquick.com/t/how-to-restrict-particular-metric-with-custom-date-filter/9822/4 "2023-03-07T16:49:29Z")

</div>

Instead of subtracting dates you need to add.

To get the previous years date you need to add it to the previous year so that it matches up with the current one.

sum(ifelse(Date field \> addDateTime(12,‘MM’,${date}) AND Date field \<= ${date} AND {metric\_desc}=‘Occupancy’,value1,NULL)) /  
sum(ifelse(Date field \> addDateTime(12,‘MM’,${date}) AND Date field \<= ${date} AND {metric\_desc}=‘Occupancy’,value2,NULL))
