2

Example of a date selector that works with start and end date pickers

 

You are probably already familiar with using a start and end date picker to select your data.  To do this you have to create two variables and typically you set the output format to epoch.

 

https://support.klipfolio.com/hc/en-us/articles/216182377-Using-Date-and-Time-Formats

 

https://support.klipfolio.com/hc/en-us/articles/215545788-How-to-build-User-Input-Control-components

 

But did you know you can enhance the Klip by adding a drop-down list to allow a user to display the data by day, week, month, or even year.

 

For example, if I select the dates 01/05/2016 and 02/05/2016 for my start and end dates in my date picker, and then I select day from the drop-down list the result is 01/05/2016 and 02/05/2016.  However, if I select month, then the result is all the data for May.

 

 

To set this up, you would need to use the BETWEEN and SWITCH functions.

 

https://support.klipfolio.com/hc/en-us/articles/215547698-SWITCH-function-

 

https://support.klipfolio.com/hc/en-us/articles/215547608-BETWEEN-function

 

The SWITCH function is specifying the start formula and the end formula for each period selection.

 

In this example, the start date picker variable is called startperiod and the end date picker variable is called endperiod. 

The variable for the drop-down list is called groupingperiod and uses the following formula for the sub-component Values:

 

ARRAY) “day”, “month” , data  )

 

To set up the Bar/Line Chart you might use the GROUP and GROUPBY function.

 

For example, with a data source that looks similar to this one.

 

ga:date

ga:sessions

20160401

10

20160402

20

20160403

15

20160404

25

20160405

30

 

 

 

 

 

For example, for the X:Axis, the formula might look like this.

 

GROUP(  SELECT(  SWITCH( groupingperiod , “day” , SLICE( A:A ) , 

 “month” , DATE_CONVERT( SLICE( A:A ) , “yyyyMMdd” , “yyyy-MM” ) ) , 

(BETWEEN( DATE( SLICE( A:A ) , “yyyyMMdd” ) ,

 SWITCH( groupingperiod , “day” , startperiod ,

“month” , DATE_STARTOF( startperiod , month ) ) ,

 SWITCH( groupingperiod ,  “day” , endperiod , 

“month” , DATE_ENDOF( endperiod , month ) )

) ) ) )

 

For example, for the Series, the formula might look like this.

GROUPBY(  SELECT(  SWITCH( groupingperiod , “day” , SLICE( A:A ) ,

 “month” , DATE_CONVERT( SLICE( A:A ) , “yyyyMMdd” , “yyyy-MM” ) ) ,

 (BETWEEN( DATE( SLICE( A:A ) , “yyyyMMdd” ) ,

 SWITCH( groupingperiod ,   “day” , startperiod ,  “month” , DATE_STARTOF( startperiod , month ) ) ,

 SWITCH( groupingperiod ,  “day” , endperiod , 

“month” , DATE_ENDOF( endperiod , month ) )) ) ) ,

SELECT(  SLICE( B:B ) , (BETWEEN( DATE( SLICE( A:A ) , “yyyyMMdd” ) ,

SWITCH( groupingperiod ,  “day” , startperiod ,“month” , DATE_STARTOF( startperiod , month ) ) ,

SWITCH( groupingperiod ,  “day” , endperiod ,  “month” , DATE_ENDOF( endperiod , month ) )) )  ) )

 

Remember, you can use the keyboard shortcut keys CTRL+C and CTRL+V to copy the formula from the X:AXIS to the Series, and then change the GROUP function to GROUPBY.

 

1 comment

  • 0
    Avatar
    Eka Ponkratova

    That's super awesome! Just a small correction - ARRAY(“day”, “month” )

Please sign in to leave a comment.