How to default variable (list of dates) to current date? - grafana

For some dashboards we have a date variable to pick a date from a list of dates. The dates are queried from an elasticsearch datasource.
In our case it would be great if we could somehow set the default value to the current date.
We are using Grafana 7.1.1. I am not sure if it can be achieved at all - Currently I am thinking about extending the elasticsearch-query to put the current date on top but I don't think Grafana can set the default value based on the index.
Another idea is to use a "global" date variable for the current date which I can search for in the variable selection field and then save the dashhboard.
Any hints (including feasibility) are appreciated.

Correct, make current date first in that variable list and never Save current variables -> Grafana will preselect first value from the variable list in this case.
If you already have some saved current variables, then you need to edit dashboard model manually (export dashboard json/edit json - variable definition/import dashboard json).

Related

Grafana dashboard: automatically set a date variable to the current date

I have a Grafana dashboard with a date variable.
I always update the possible values once a day via a job to always be [currentDate - 2, currentDate - 1, currentDate, currentDate + 1, currentDate + 2] (I update the data source through the job). Sometimes the values can also differ, but the current date is always in there.
Now my users complained that the default value of that variable is always the first one, which is not always the current date. They want the default value to always be the current date (based on a predefined timezone).
I know that I can update this manually every day. Go into the dashboard, update the date and save. I do not want to do this. I want to update this automatically.
What way is there to do this? Does Grafana offer some native functionality with which to do it? Or do I have to do this with an external job or through some other means?
Make currentDate first in that variable list (yes, users may complain that it isn't in the logical order, but you can't have everything - unless you don't want to code own Grafana) and never Save current variables -> Grafana will preselect first value from the variable list in this case.
If you already have some saved current variables, then you need to edit dashboard model manually (export dashboard json/edit json - variable definition/import dashboard json).

Tableau Dashboard Default set to Yesterday by using Date Parameter

I have created daily dashboard which shows the data for single date selected from DATE PARAMETER (with ALL value). Which is OK for me that I can see the data for any date I want.
But the problem is when I open my dashboard it is showing data for date which I selected in date parameter while publishing the Dashboard to Server/Online and Instead of that I want set it default to Yesterday.
i.e. when I open my dashboard first time it should show yesterday's data and also there should option to change date as well to see another date data.
Can we achieve this using DATE PARAMETER (with ALL values)? If it is not possible then is there any other way?
Please Help!
Use a relative date filter instead of a parameter. Just be sure to save and publish the workbook with Yesterday as the relative date value.
1, Create a calculation field d_yesterday, formula is TODAY()-1
2, Create a parameter, data type is Date, value when workbook opens set to d_yesterday
3, use the Date parameter in other calculations fields, or insert parameter into custom SQL query.

SSRS Preset or Custom Date Selection on Report

I currently have a report with the ability to select a start and end date. I was curious if you could make have both preset and the option for a custom selection
Selection:
Current Week, or
Previous Week, or
Custom Date Range.
Thanks,
Take a look at cascading parameters.
The link above seems to focus more on getting your cascading parameter values from a query, but you probably don't want that for a date - as far as I am aware, setting Available Values for a date parameter limits you to a dropdown list of dates, instead of the calendar which is generally easier to use. It is still a good background on how cascading parameters work though.
To do this with expressions for the default start/end date, you would basically want the first parameter to be a choice between "Current Week", "Previous Week", and "Custom Date Range". You would display those labels to the user, but the values can be whatever you want - for my test I just used 1, 2, and 3.
Then, you would set up 2 more parameters, one for the start date and one for the end date. Make sure the data type is Date. You will want to set up default values for these based on the value of the first parameter. I would do this with an expression such as the expression below for the start date. You also may need to modify this a bit depending on how you define the week - is the "Current Week" just the previous 7 days, or is it the latest Monday through today, or something else, etc.
=Switch(
Parameters!FirstParam.Value = 1, DateAdd("d", -7, Today()),
Parameters!FirstParam.Value = 2, DateAdd("d", -14, Today())
)
In this case, you don't even need to account for the 3rd option, because if the user wants a custom date range then you do not want the start and end date to fill in with any default values. You would need a similar expression for the default end date as well.
Since you want the user to be able to enter a custom range as well if they were to select the third option, you do not want to fill in the Available Values for the start/end date parameters, as the user would then not be able to select any date (at least as far as I am aware - if there is a workaround to that, I would love to see it, as that would be something I would like to use myself).
A possible downside to this approach is that if the user begins by selecting Current Week and then changes their mind to Previous Week, the start/end dates will not change to the Previous Week. You can read more about why this happens here, but essentially: since the values that are already filled in after selecting Current Week are still valid (they are dates, which is the only criteria for those parameters since no available values are set up), they will not refresh after changing the selection. The fix for this is to define the Available Values, but as mentioned above, this will then stop the user from entering a custom date range.

Tableau - Dynamic Parameter Reference

I have a series of parameters in Tableau corresponding to every month in the coming years. The parameter names are all in the format Name - YYYY-MM-DD where YYYY-MM-DD is the corresponding beginning of the month. I would like to reference the parameter using the current month value (e.g. 2017-11-01).
How can I reference a parameter using something like the following:
["Name "+DATEFUNCTION()]
where DATEFUNCTION() will create the date in the appropriate format. However, this clearly does not work.
Referencing parameter name dynamically is not possible.
You can either try to implement your logic of pulling data out of parameters as a single calculated field or use a secondary datasource containing Date,Value,DummyLinkToPrimary fields and filter it on date.

Drupal 7 and Page Manager: add Selection rules based on dates

I have a content type article with a field date.
I am trying to fire a variant from Page Manager by defining a selection rule based on a date field.
What I am trying to do is applying this variant when
the node type is article
field date, start date < now < field date, end date
I can define the first condition but I can't figure out how to make a condition based on a date. Is it possible or not? I couldn't find more information about this.
Thanks
I managed to do this finally by writing a PHP Code Selection Rule.
I got from the exposed $contexts variable the start and end values for date field and I wrote a simple condition to check if "now" is in between the two dates.
Beware that the dates are stored in UTC format in the field and your site/users might be in a different timezone.