Count Docs
Date groupings
How to let users choose a date aggregation level (e.g. day, month, year)
It's often helpful to allow your readers to control more complex aspects of a SQL query, such as the granularity of a date aggregation. In Count this is typically implemented in 3 steps:
  1. 1.
    Define the acceptable inputs for the reader to choose from
  2. 2.
    Create an interactive control to display these options
  3. 3.
    Use the selected option to modify the final SQL query
The reader will just see a control and, say, a visual which updates accordingly. For example:
The appearance of this example when the notebook is published
This concrete example is displayed below:
  1. 1.
    The period cell defines a column called value, which just contains 'Monthly' and 'Yearly' - these are the options a reader may pick.
  2. 2.
    The timeframe control displays these options, with a reader-appropriate title.
  3. 3.
    The avg_duration cell uses the selected value from timeframe (via a cross-join) to change the truncation of the datetime column.
An example of a setup for a dynamic SQL query (here using BigQuery syntax)
Last modified 7mo ago
Copy link