Custom MySQL - Relative Date (from Dashboard) not working

Hi all, I am struggling heavily with a simple, custom MySQL query. I basically want to get the SUM() of some contents but can not figure out how to make the MySQL query customizable, so the dashboard can apply the "Relative Date" filter.

Let's say this is my MySQL query:

SELECT SUM(cost) FROM my_table WHERE [[ what do I put here? ]]

I want to use the "Relative Date" filter from the dashboards (see screenshot above). Any idea how to succeed?

Hi @lars
You are looking for SQL variables:
https://www.metabase.com/learn/building-analytics/sql-templates/field-filters.html

1 Like

Thank you very much! In practice, how would it look for the specific case stated above?

Edit: Never mind @flamber
My problem was to use the custom filter type “Date” and not “Field Item”… Issue solved.

@lars SELECT SUM(cost) FROM my_table WHERE {{mydatefilter}} and use the sidebar to connect to a date column - but remember to read the article - specially the “gotcha” aka limitations.

@lars Okay. You are basically seeing this issue, where you would have had an option available if you were using Single Date on the dashboard filter:
https://github.com/metabase/metabase/issues/5781 - upvote by clicking :+1: on the first post