# Need help on filtering charts based on date

**URL:** <https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880>\
**Category:** Ask for Help\
**Created:** [July 13, 2023, 8:53pm UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880 "2023-07-13T20:53:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teejay\_Oyeniran](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/teejay_oyeniran/32/61251_2.png) [@Teejay\_Oyeniran](https://community.glideapps.com/u/Teejay_Oyeniran)\
**Post date:** [July 13, 2023, 8:53pm UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/1 "2023-07-13T20:53:11Z")

</div>

l created a choice component “Today”, “This Week”, “This Month”, “This Year”, “Select a Date Range” from the data source “TimeFrame”… l have a record of date on another date source “Sales”… l want the choice component to have the ability to filter these stats “Contract, Offers, Closings” whenever l select a choice

 ![Glide1](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/3/0372b6f9710a380c4d572554dcf10bb0d8a5d2dc.png)  
 ![Glide2](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/6/76a06329e7ec3e36126dbe1e9eef6d597f4da693.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [July 13, 2023, 9:37pm UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/2 "2023-07-13T21:37:03Z")

</div>

I brief overview of what I would do…take the values from your selected choice and the custom date inputs, and bring them into the table that contains the chart data using Single Value columns. Then you’ll need math columns to subtract the number of days for a week, month, year, etc. Followed by IF columns to determine which rows are in range. Ultimately you want a true/false value that you can use for filtering.

It’s a bit complicated to explain, and there are some open ended questions. Does a week mean the past 7 days or the current week. Did a month mean the past 30 days, 31 days, 28 days, or the current month. Does Year mean the past 365 days or year to date. All of those things will determine how you set up your math columns.

---

<div class="post-metadata">

**Author:** ![Teejay\_Oyeniran](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/teejay_oyeniran/32/61251_2.png) [@Teejay\_Oyeniran](https://community.glideapps.com/u/Teejay_Oyeniran)\
**Post date:** [July 13, 2023, 10:11pm UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/3 "2023-07-13T22:11:17Z")

</div>

The week means the current week likewise the current month and year… l’ll appreciate it if you can help me out… l have been on this since last two weeks.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [July 14, 2023, 12:10am UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/4 "2023-07-14T00:10:16Z")

</div>

That makes it a bit easier.

First, in your choices table, create 4 math columns like the following, and replace Now with Now:

TodayNow:  
`YEAR(Now)*10000+MONTH(Now)*100+Day(Now)`

WeekNow:  
`YEAR(Now)*100+WEEKNUM(Now)`

MonthNow:  
`YEAR(Now)*100+MONTH(Now)`

YearNow:  
`YEAR(Now)`

* * *

Next create an IF column in your choices table that looks like this. It will check the choice value in each row and return the appropriate math column value. The final ELSE value will be the word ‘DateRange’:

```auto
IF choice is Today then TodayNow
ELSEIF choice is Week then WeekNow
ELSEIF choice is Month then MonthNow
ELSEIF choice is Year then YearNow
ELSE 0

```

* * *

Change your choice component to display the words like you are now, but have it write the value from the IF column above instead.

* * *

I don’t know how you are handling the custom date range, but I assume it’s two date columns. I would create two math columns to convert the date into a number like above:

`YEAR(FromDate)*10000+MONTH(FromDate)*100+Day(FromDate)`

`YEAR(ToDate)*10000+MONTH(ToDate)*100+Day(ToDate)`

* * *

In your chart data table add three single value columns. One to retrieve the value from the selected choice, and two to retrieve the from and to math values from the custom dates.

* * *

In your charts data table, I would set up 4 math columns as follows. You will replace date with the date value in you chart data rows.

FullDate:  
`YEAR(Date)*10000+MONTH(Date)*100+Day(Date)`

WeekDate:  
`YEAR(Date)*100+WEEKNUM(Date)`

MonthDate:  
`YEAR(Date)*100+MONTH(Date)`

YearDate:  
`YEAR(Date)`

* * *

Now your charts data table should contain 3 single value columns and 4 math columns. Add a final IF columns like this:

```auto
IF FullDate = sv-Choice then 'true'
ElseIF WeekDate = sv-Choice then 'true'
ElseIF MonthDate = sv-Choice then 'true'
ElseIF YearDate = sv-Choice then 'true'
ElseIF sv-choice > 0 then 'false'
ElseIF FullDate < sv-FromDate then 'false'
ElseIF FullDate > sv-ToDate then 'false'
Else 'true'

```

* * *

After all of that, you should be able to filter your chart where the final IF column value is checked (‘true’). I’m sure there are better ways to set it up with some javascript, and I may have missed something, but this is probably the easiest to understand.

---

<div class="post-metadata">

**Author:** ![Teejay\_Oyeniran](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/teejay_oyeniran/32/61251_2.png) [@Teejay\_Oyeniran](https://community.glideapps.com/u/Teejay_Oyeniran)\
**Post date:** [July 15, 2023, 4:33am UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/5 "2023-07-15T04:33:21Z")

</div>

Thank you very much for your response… it’s solved.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [July 16, 2023, 4:34am UTC](https://community.glideapps.com/t/need-help-on-filtering-charts-based-on-date/63880/6 "2023-07-16T04:34:12Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
