[v7.0.1] Interval variable to switch between labour days and weekends

Hello, I am new to the community and Grafana.

Recently, I was wondering whether it was possible to add a dashboard variable to work as a quick range, which would control what days of the week should be shown on a plot or chart. For instance, there could be only two values available, one named labours_day that would represent the days of the week from Monday to Friday, and another, weekend, that could include Saturday and Sunday.

I know about the existence of time regions, in the panel edit options, that, since v6.3, allows to colour those ranges, but it does not let the user decide which data should be selected.

Thanks in advanced!

By the way, I am using elasticsearch v6.5.4 as datasource. Thanks!

Hi!

Are you talking about having an additional set of time ranges in the time picker? Or is this something you want to use directly in your queries?

/Tobias Skarhed

Hello Tobias,

Thanks for your response. It has to do with queries, for instance, I want to be able to show only data from days between Monday and Friday in the “Last 30 days”. I was able to add an interval variable named “day”, and the tried to filter date in the panel query using the Lucene expressions of elasticsearch (something like doc[“field”]).date.dayOfWeek. Unfortunately, it did not work, since no data points where found.

I will upload pictures from the panel soon.
Regards,
Gastón Rial

Hi,

I have managed to do what I intended from the elasticsearch API, by adding a script to the filter query. For instance, to get only data from Tuesday, I sent a request like the one below.
URL: http://127.0.0.1:9200/_search?pretty

BODY (Content-Type: application/json):
{
“size”:0,
“query”:{
“bool”:{
“filter”:[
{
“range”:{
“time_local”:{
“gte”:1590967105145,
“lte”:1591571905145,
“format”:“epoch_millis”
}
}
},
{
“script”:{
“script”:{
“lang”:“painless”,
“source”:“doc[‘time_local’].date.dayOfWeek==2”,
“params”:{
“day”:2
}
}
}
},
{
“query_string”:{
“analyze_wildcard”:true,
“query”:“data:value”
}
}
]
}
},
“aggs”:{
“2”:{
“date_histogram”:{
“interval”:“20m”,
“field”:“time_local”,
“min_doc_count”:0,
“extended_bounds”:{
“min”:1590967105145,
“max”:1591571905145
},
“format”:“epoch_millis”
},
“aggs”:{
“1”:{
“cardinality”:{
“field”:“count_value”
}
}
}
}
}
}

Nonetheless, I do not know how to translate this query into grafana query editor page.

Regards,
Gaston

I am not too familiar with Elasticsearch, so I’m not quite sure if I can help you any further with it :frowning:

ok, thanks anyway :blush:!

Maybe there is a way to filter the day of the week from the Grafana JSON model :thinking:, is anyone aware if this is possible?