2

New Date Filtering - Date Drop Down / Period Selector

Hey Everyone,

In this community post, I am going to go over a specific example with our awesome new date filtering!

 

This example is a very common one, where you are looking to have a dropdown list with multiple different date ranges of different types.  So for example, having a dropdown that would allow you to select between “Last 7 Days”, “Month to Date”, “Last Quarter”,  and more


 

 

Before our new filtering, this type of filtering would require you to use a SWITCH statement to outline each case in both the X-axis and the series you were using.  Many of you will be familiar with the article on this that you can find here

 

With our new filtering, this becomes a much more simple process with significantly less formula work!

 

The first step we need to take is to add the empty bar/chart (or whichever component you would like to work with), as well as a User Input Control

 

Next, we are going to use an array function to assign our desired Labels to our User Input Control.  The Labels are going to be what is displayed in the User Input Control for the users to select.  For this example, I chose to use:

 

Now, we are going to assign the corresponding Values to the User Input Control.  The Values are what is going to be assigned to the variable when the corresponding Label has been selected.  One important thing to remember is that the order does matter as each element from both the Values and the Labels will be assigned to each other based on their place in the Array.  Also, the Values and the Labels need to have the same number of items in their arrays.  For the Labels above, here are the corresponding Values:

 

One thing that jumps out right away, and you might be confused about is “why if our first Label is “Last 7 Days” do we have a “6” as the Value?”.   This is a great question, and what we need to remember is that we will be using out “Last Full” filter option which does not include today because today has not finished and therefore is not a “Full Day”.  This is also be the reason why in our COUNT_DAYS function we are using YESTERDAY instead of TODAY.

 

Now that we have built out our User Input Controls, its time to move onto the chart!

 

The first thing we will do is populate our X-Axis of the chart.  To do this, we just need to simply select the column that contains our dates:

 

We will also want to go under the properties tab and ensure that the “Format As” dropdown is set to “Date/Time”, our “Input Format” matches the format of the dates in the data, and the “Display Format” is how we would like it to appear on the X-Axis.  For example if you would like the data to aggregate by month, your Display Format will be: MMMM

 

Next we will select the data for our series.  Again, all we need to do is select the column that our data is in.  For my example, I want to show “Sales Target” which is in column F:

 

Now that all our data has been selected, we can move onto our filtering.  To access our filter, we want to select our X-Axis in the component tree, right click on it and select “Edit Filter”:

 

Once in the filter, we will select the “Condition” tab.  Now we will start building out our filters!

 

For the first filter, we are going to select “Last Full” from the dropdown. Then we are going to select the down arrow which will give us a dropdown of all the variables associated with our account.  We want to select the variable we assigned to the User Input Control we have built.  We will then want to select “Day(s)” because with our count days function we got the relative values of each time period in days.

 

With this filter in place we have all of our data except for today because as mentioned above, today is not a full day.  Not to worry!  We will now click the “Add Condition” button to add another condition to our filter.  We then need to select “Match Any” to change this to an OR  condition because we want data that is in either the number of days our variable has specified from today OR data from today

 

And with that, we are done! Now as you change the User Input Control, it will filter the data for the time periods you laid out in your User Input Control

 

As always, if you have any questions please do not hesitate to reach out!

Garrod

18 comments

  • 0
    Avatar
    Brice Sloan

    very cool!

  • 0
    Avatar
    Utku Demirhan

    Hi. This doesn't work on repeating days. For example

    Date                  LP

    2018-02-01 .     a

    2018-02-01 .     b

    2018-01-01 .     b

     

    How can use period selector in this kind of data?

     

    Thanks

     

  • 0
    Avatar
    Scott Lawrence

    Hi Utku,

    Thanks for raising your question in the community.

    Can you describe your situation and what outcome you are trying to achieve?  I tried a number of scenarios using the filter and your example that achieved expected results.  I may not have looked at exactly what you were trying to achieve.

    Thanks,

    Scott.

     

  • 0
    Avatar
    Angelo Reyes

    Hi All,

    How to use this filter when my period selection is "1stQuarter", "2ndQuarter", "3rdQuarter" & "4thQuarter"?

    My data table is shown like this:

    Column 1 - will be my series; then Columns 2 and so on... - are the months of the year (January to December) in MMMM yyyy format

    I was able to successfully use switch on a previous klip using UIC to control a table.

    What specific function (relative to date manipulaion) or combinations of function and filter can be used for a chart?

    Thanks for the help!

     

  • 0
    Avatar
    Janice Janczyn

    Hi Angelo,

    Assuming you're always working with current year data, you would use the DATE_UNITVALUE function to get the quarter value of a given month. Using your data for example, you dates must first be converted to Unix format (they are in MMM-yy format) before being passed into the DATE_UNITVALUE function:

         DATE_UNITVALUE( DATE( 1:1, "MMM-yy" ), quarter )

    returns blank,blank,1,1,1,2,2,2,3,3,3. Note that this returns only the quarter, regardless of year. These results can then be matched with your period selector. If your UI labels are 1stQuarter,2ndQuarter,3rdQuarter,4thQuarter, the corresponding values could simply be 1,2,3,4. 

    Note that Klipfolio functions are designed to work with columns of data so if you can re-orient your data such that the dates are in 1 column and the items in your first column become your column headers, working with the data becomes more straightforward.

    Thanks,
              Janice

  • 0
    Avatar
    John Wedderburn

    This was great - clear instructions with an explanation of why the steps are required. More please!

  • 0
    Avatar
    Garrod Houweling

    Hey John,
    Really appreciate the feedback!

    We are always looking for new content to publish in our community!

    Do you have any suggestions on articles or a specific use case you would like to see that would benefit users in Klipfolio?

    Always open to suggestions!
    Garrod

  • 0
    Avatar
    Devika Nagarkar

    Hi,

    I have implemented the whole process but I'm getting an error while editing the filter for the x-axis. I'm getting this error after selecting my variable - ' Relative amount must be a positive integer less than 10000.'

    Can you please help ?

  • 0
    Avatar
    Janice Janczyn

    Hi Devika,

    Please check the value assigned to your variable in the Klip Editor: select Manage Variables from the Advanced Tools menu at the top (to the right of the klip name). Ensure the variable is set to a positive integer < 10000. 

    Thank you,
                  Janice

  • 0
    Avatar
    Atomic Revenue, LLC admin

    how could you set this up to report of the last 8 quarters or so?  also, is there a way to make the drop-down dynamic always show the previous 8 quarters so you don't have to rely on hard coded values?

  • 0
    Avatar
    Janice Janczyn

    Hello,

    The drop-down is dynamic as it uses our date/time functions to calculate date relative to the current day (TODAY()). For example, DATE_STARTOF( TODAY(), month) will always return the first day of the current month and YESTERDAY will always return the previous day, both in Unix format which is an integer: the number of seconds since January 1, 1970 midnight GMT.  To add a Last 8 Quarters (including current quarter) to the drop-down,

         Labels: add "Last 8 Quarters" to the ARRAY
         Values: use the formula, COUNT_DAYS( DATE_STARTOF( TODAY(), quarter, -7 ), YESTERDAY() )

    I hope this helps!

    Thanks,
           Janice

  • 0
    Avatar
    Manu Goyal

    Hi,

    I have monthly data, I want to show by user input control as in figure. And also explain about use of Day, week, month, year in filter condition. Kindly help.

  • 0
    Avatar
    Adam Doogan-Smith

    Hi Manu!

    If you want to filter by these period, you can reference this tutorial which will walk you through how to set this up: https://support.klipfolio.com/hc/en-us/articles/215548158-Common-User-Input-Control-scenarios-Counting-all-tickets-by-quarter-by-month-by-weekday

    I hope this helps!

    Adam

  • 0
    Avatar
    Jeremy Kocian

    I've tried multiple different methods to setup a user control for $datePeriod, including this method. Everything returns errors. This particular one says that "relative amount must be a positive integer less than 10000."

     

    My variable is datePeriod (name) with variable "datePeriod" 

    I'm using the date column of my data with is in yyyy-MM-dd'T'HH:mm:ssZ format. 

     

    Prior to adding a user input the data was displaying perfectly, now I just have a red dot on the graph and all of the series have exclamation points. My goal is to be able to have these on each Klip on the board, but I can't even get one to work. :/ 

     

  • 0
    Avatar
    Sarah Ramirez

    "I've tried different methods using the steps in this article, as well as SWITCH function. However, I am not able to get either the ARRAY in User Input Control or SWITCH function to work. I have attached screen shots for reference. For both it creates the labels but when I try to have the bar graph change based on drop down option selected nothing changes. Can anyone provide insight into what is causing the issue:

    ARRAY function from article 

     

    SWITCH Function 

     

  • 0
    Avatar
    Meggan King

    Hi Sarah - From the screenshots, it looks like your brackets are not aligned correctly, so I can't easily tell how the formulas will work with the variables. I'd suggest you reach out the support team at Klipfolio. Be sure to enable support access and tell them which Klip you are working on.

    Thank you

    Meggan

  • 0
    Avatar
    Sarah Ramirez

    Hey Meggan

    Unfortunately, I am not able to reach out to the support team due to cost. Can you please clarify more on how brackets should be aligned? Are they misaligned for both screenshots?

    Thank you.

    Sarah Ramirez

  • 0
    Avatar
    Meggan King

    Hi Sarah -

    Support is free to everyone. You just email them directly at support @ klipfolio . com

    They will advise on options for you to solve the issue since your screenshots are not clear on where the issue might be.  

    Thanks

    Meggan

Please sign in to leave a comment.