Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression as a default value for date variable #3156

Open
piranha opened this Issue Aug 10, 2016 · 9 comments

Comments

Projects
None yet
6 participants
@piranha
Copy link

piranha commented Aug 10, 2016

Right now default value for date can only be an exact date. I'm not sure how to make a dashboard which by default shows data for the last month, but provides a way to see earlier data.

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@salsakran

This comment has been minimized.

Copy link
Contributor

salsakran commented Aug 17, 2016

as mentioned in #3211

You should probably use a "relative date" dashboard filter widget -

screen shot 2016-08-16 at 5 30 39 pm

screen shot 2016-08-16 at 5 30 49 pm

we don't support 2 weeks out of the box, but we can probably add that.

You would then use something similar to

SELECT count(*)
FROM products
WHERE {{created_at}}

and mark created_at as a field filter.

@piranha

This comment has been minimized.

Copy link
Author

piranha commented Aug 17, 2016

There is a problem though, this date is filtering more than a single field - it's filtering 4 fields across 3 tables (the query is quite complex). Is it possible somehow to handle that?

@salsakran

This comment has been minimized.

Copy link
Contributor

salsakran commented Aug 17, 2016

Can you share the entire sql query? Not sure if it's possible with the field filter tag, but if it isn't I'd like to try to figure out a way with raw date tags if possible.

@camsaul

This comment has been minimized.

Copy link
Member

camsaul commented Sep 3, 2016

@piranha

This comment has been minimized.

Copy link
Author

piranha commented Sep 9, 2016

Oops, sorry, managed to miss notifications!

So the code is something like this:

WHERE c.starts_at <= {{date}}::date + ('1 day'::interval)
    AND c.finishes_at >= {{date}}::date
    AND o.created_at >= {{date}}::date
    AND o.created_at <= {{date}}::date + ('1 day'::interval)

And that should be the same date for two different tables. :)

@jesusrtc

This comment has been minimized.

Copy link

jesusrtc commented Sep 26, 2016

+1

When I try to add a dynamic filter of date since creating the question it is not possible (even if the query is very simple).

select * 
from table t
where t.created_at::date = {{date}}

image

Then allow the option of dynamic dates in dashboards and if it's possible in pulses.
I need to have a dynamic dates to create a pulse for example.

@igisho

This comment has been minimized.

Copy link

igisho commented Apr 7, 2017

any news on this request?

@camsaul

This comment has been minimized.

Copy link
Member

camsaul commented Sep 13, 2017

Hey everyone, one way we prioritize issues is by sorting them by the number of 👍 reactions on each issue's description. So instead of leaving +1 or 👍 comments, please just upvote by adding a reaction to the issue description.

@govorec

This comment has been minimized.

Copy link

govorec commented Sep 20, 2017

For now, I think you can handle default values of variables in reports.
Actually, by handling the absence of value in SQL instead of setting up the defaults in UI:
c.starts_at > coalesce([[{{date}}::date,]] current_date - '1 month'::interval)

Just bind dashboard's variable with report's variable and leave it blank, so report will handle it by itself.
A good point, you can have different default values for one variable in different reports of the dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.