# Create a dynamic filter or parameter to display month to date KPI

**URL:** <https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712>\
**Category:** Q&A\
**Tags:** parameters, calculations, Business-Intelligence-Engineer, quick-sight\
**Created:** [July 17, 2024, 4:17pm UTC](https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712 "2024-07-17T16:17:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rus](https://avatars.discourse-cdn.com/v4/letter/r/51bf81/32.png) [@Rus](https://community.amazonquick.com/u/Rus)\
**Post date:** [July 17, 2024, 4:17pm UTC](https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712/1 "2024-07-17T16:17:13Z")

</div>

Hi All, I have created a KPI which shows the percentage of total sales MTD (month to date). This is month to date KPI.

I created a parameter for this KPI called “First Day of the Month” which is Start Date of Previous Month and “Last Day of the Month” which is End of previous Month and added this to the filter.

I have a “Snap Date” filter on the control line which has a date of June 30th 2014.

Is there a way to create a dynamic parameter or calculate field where if I select the snap date as May 31st, then it would basically show me the percentage of total sales KPI for the month of May?

Now because of my current parameter, it is just giving me June Data but I want this to be a dynamic KPI where if I select the previous month in my snap date, it should show me the percentage for that particular month. The data should be based on month to month basic hence I had to create this parameter but I want it to be dynamic.

---

<div class="post-metadata">

**Author:** ![murili](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/murili/32/21621_2.png) [@murili](https://community.amazonquick.com/u/murili)\
**Post date:** [July 17, 2024, 5:18pm UTC](https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712/2 "2024-07-17T17:18:56Z")

</div>

To create a dynamic KPI that shows the percentage of total sales for the previous month based on the selected “Snap Date”, you can use a combination of calculated fields and parameters. Here’s an approach you can try:

1. **Create a Calculated Field for the Previous Month** :

2. **Create a Calculated Field for the Last Day of the Previous Month** :

3. **Use the Calculated Fields in the KPI** :

4. **Make the KPI Dynamic** :

Here’s an example of how the calculated fields might look:

```auto
# Previous Month Start Date
DATEADD('month', -1, {Snap Date})

# Previous Month End Date
LASTDAY(DATEADD('month', -1, {Snap Date}))

```

You can then use these calculated fields in your KPI visual, and the percentage of total sales will be displayed for the previous month based on the selected “Snap Date”.

---

<div class="post-metadata">

**Author:** ![Rus](https://avatars.discourse-cdn.com/v4/letter/r/51bf81/32.png) [@Rus](https://community.amazonquick.com/u/Rus)\
**Post date:** [July 17, 2024, 5:34pm UTC](https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712/3 "2024-07-17T17:34:36Z")

</div>

Hi. I dont see DATEADD and LASTDAY functions in Quicksight. Are there alternative functions?

---

<div class="post-metadata">

**Author:** ![Xclipse](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/xclipse/32/20455_2.png) [@Xclipse](https://community.amazonquick.com/u/Xclipse)\
**Post date:** [July 26, 2024, 4:49am UTC](https://community.amazonquick.com/t/create-a-dynamic-filter-or-parameter-to-display-month-to-date-kpi/32712/4 "2024-07-26T04:49:05Z")

</div>

Hi @Rus, here is the syntax:

```auto
addDateTime(-1, ‘DD’, addDateTime(1, ‘MM’, truncDate(“MM”, now())))

```

Calculation Reference:

> [@Period Over Period and Other Date Comparison Calculations (YoY, MoM, YTD, Rolling 90 days, etc)](https://community.amazonquick.com/t/period-over-period-and-other-date-comparison-calculations-yoy-mom-ytd-rolling-90-days-etc/564/1):
>
> Often you may want to create tables and other visuals which display multiple fields that are all ‘filtered’ to different date periods, as well as period-over-period fields. However we can’t use normal filters for this since filters get applied to all fields in the visual. Conceptually in this solution we are building the filters directly into the calculated field itself (using the ifelse logic), so that each field can have a different ‘filtered’ time period. You can then do whatever math you wan…

Did this solution work for you? I am marking this reply as, “Solution,” but let us know if this is not resolved. Thanks for posting your questions on the Quick Sight Community!
