I am trying to add a filter ( week_year) which I define in the first line (meaning that we don't have that format in the WH)
SELECT
CONCAT( cast(year_of_week(dt) as varchar) , ' ', 'W', cast(week_of_year(dt) as varchar)) as week_year,
dt as date,
country_cd as country,
-- more fields / not relevant to the question here......
FROM table
WHERE date(dt) > date('2023-01-01') AND
TRUE
[[AND {{date}}]]
[[AND {{country}}]]
[[AND {{week_year}}]]
GROUP BY 1, 2,3
ORDER BY dt,country_cd
I suggest you build that field in the DB to use field filters or use the new filters we shipped in 46 which allow you to use manually defined filter values
Thanks a lot Luiggi! Given that it might not be possible to add it as a new field on the DB, can you please give me more details about the filters you mentioned?
If there is any walkaround for the user to be able to change the date granularity based on a filter (say weekly/monthly) I'd be more than happy to go with that..
So in your SQL you will need to do something like this:
GROUP BY (CASE {{aggregation}}
WHEN "d" THEN datefield
WHEN "w" THEN week(datefield)
WHEN "m" THEN month(datefield)
ELSE datefield
END )
{{aggregation}} is a text field (required, default "d" ) and 'datefield' being the column where the date is stored in your table
Then you can create a dashboard filter (text filter) and link it to {{aggregation}} in the question so you would be able to dynamically change the sate granularity with the {{aggregation}}