Hi everyone!
I’m looking for good solution of the following problem:
I have daily data for sales and I would like to have visualisation in which I can switch between displaying sum(sales) in different time periods (daily, weekly, monthly).
In ideal version I have Date-Range parameter where I can chose the range of dates between which I can see the values and dropdown parameter where I choose time periods (day/week/month).
As an example: it’s 21st of September today and I’ve chosen this month in Date-Range parameter. When on day/week/month parameter I choose:
“day”, I’ll see 21 bars, one for each day
“week”, I’ll see 3 bars, one for each Monday this month
“month”, I’ll see only 1 bar, from the beginning of this month
Thank you @xavier-d this is very interesting direction.
This solution works almost as what I need. There is one problem I found with selecting “day” and looking for the whole year time-span:
as DATEPART({{my_dropdown}}, date) return day as int type, the graph is showing 31 bars (one for each number for day in date), not 1 bar for each day (on September 21st it should be 264 bars).
@TOc To address the issue with 31 bars you probably don’t want the datepart function in this case, you want the actual date. The logic can get pretty complex to switch between the two. In order to simplify this you might consider creating a calendar dimension table with one row for every date and capturing all the relevant attributes for these dates. There are plenty of examples on the web as to how this might look. But you might be interested in something like:
Then you could join to this table in your query and just specify the column names (dt, year_month, year_week) in the filter you want using the dropdown that @xavier-d suggested. The calendar dimension table would also allow you to better align what defines a week/month with your business (does a week start on Monday/Sunday, are we looking for fiscal months instead of calendar months?). This table would also be re-usable for a lot of other queries as well.
SELECT
EXTRACT(YEAR FROM creation_time) AS YEAR,
CASE
WHEN "{{ period }}" = "DAY" THEN DATE(creation_time)
ELSE EXTRACT({{ period }} FROM creation_time)
END AS period,
MIN(DATE(creation_time)) AS Date,
COUNT(*) AS value
GROUP BY period, year
ORDER BY Date```
1 Like
Login or sign up disabled while the site is in read only mode