# Changing Grafana Query Options (Max Data Points) based on a dashboard variable

**URL:** <http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273>\
**Category:** openHistorian\
**Created:** [June 5, 2024, 1:04pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273 "2024-06-05T13:04:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardlira](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ricardlira/32/1314_2.png) [@ricardlira](http://discussions.gridprotectionalliance.org/u/ricardlira)\
**Post date:** [June 5, 2024, 1:04pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/1 "2024-06-05T13:04:03Z")

</div>

Hi there!

One of the issues we are facing while working with OH+Grafana is the download time for large periods (\>3 hours of data). One of the ways to facilitate this search is to decrease the “Max data points” in query options in Grafana “Data source” fields.

What I’m looking for is to allow the user to decide if he/she want low or high resolution data. For large data navigation the “low resolution” would be selected (let’s say 300 points) and for the “high definition” that it would be the largest possible (“auto”). To do this I need to add a $var in this field but Grafana doesn’t allow me to do that. Is there another method to do so using the OH plugin features?

Thanks!  
Ric

 ![image](http://discussions.gridprotectionalliance.org/uploads/default/original/2X/2/2ca01a4efcd08ad248bf252827c1024ec18de91c.png)

---

<div class="post-metadata">

**Author:** ![ritchiecarroll](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ritchiecarroll/32/2_2.png) [@ritchiecarroll](http://discussions.gridprotectionalliance.org/u/ritchiecarroll)\
**Post date:** [June 5, 2024, 1:33pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/2 "2024-06-05T13:33:04Z")

</div>

Try the interval function: [Interval Grafana Functions](https://github.com/GridProtectionAlliance/gsf/blob/master/Source/Documentation/GrafanaFunctions.md#interval)

This is for down-sampling. If the interval value is zero, the data is at full resolution.

You can use a variable with this for the value.

---

<div class="post-metadata">

**Author:** ![ricardlira](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ricardlira/32/1314_2.png) [@ricardlira](http://discussions.gridprotectionalliance.org/u/ricardlira)\
**Post date:** [June 5, 2024, 2:00pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/3 "2024-06-05T14:00:35Z")

</div>

Great! It works precisely as expected.

 ![image](http://discussions.gridprotectionalliance.org/uploads/default/original/2X/3/3780a33b5604b4a93e7112b12dee29e47311fe2a.png)

---

<div class="post-metadata">

**Author:** ![ricardlira](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ricardlira/32/1314_2.png) [@ricardlira](http://discussions.gridprotectionalliance.org/u/ricardlira)\
**Post date:** [June 5, 2024, 3:34pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/4 "2024-06-05T15:34:29Z")

</div>

Ritchie,  
The use of OH interval() function works indeed but its performance is not like the same as manipulating Grafana’s query option (huge speed difference!). Is there a way to manipulate the “Max data points” as a var in Grafana? Sorry to come back at this point. Thanks

---

<div class="post-metadata">

**Author:** ![ritchiecarroll](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ritchiecarroll/32/2_2.png) [@ritchiecarroll](http://discussions.gridprotectionalliance.org/u/ritchiecarroll)\
**Post date:** [June 5, 2024, 9:24pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/5 "2024-06-05T21:24:32Z")

</div>

We use the `interval` parameter provided by Grafana, which is based on time range, to estimate the down-sampling resolution.

Currently, only the `Interval` function can be used to control down-sampling, but as you note, this is not the same as the resolution filter, which is very fast.

Let me think on some options here…

Thanks,  
Ritchie

---

<div class="post-metadata">

**Author:** ![ricardlira](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ricardlira/32/1314_2.png) [@ricardlira](http://discussions.gridprotectionalliance.org/u/ricardlira)\
**Post date:** [June 5, 2024, 9:44pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/6 "2024-06-05T21:44:57Z")

</div>

Right, indeed, the performance difference is significant enough to insist using Grafana “Mas data points” parameters directly. I have been searching in forums about this but I found more people asking about that rather than providing a clear answer. If interval() could mimic the same performance of grafana’s down-sampling would be great. Thanks for your effort here!

---

<div class="post-metadata">

**Author:** ![ritchiecarroll](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ritchiecarroll/32/2_2.png) [@ritchiecarroll](http://discussions.gridprotectionalliance.org/u/ritchiecarroll)\
**Post date:** [June 6, 2024, 1:56am UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/7 "2024-06-06T01:56:08Z")

</div>

I put in an update to the openHistorian Grafana adapter which will allow you to manually override the `interval` setting value for more finite control over the native openHistorian intervaled data filtering:

> <https://github.com/GridProtectionAlliance/gsf/pull/251/commits/3499667966aea5ea062f5ccf8d8f7de5124120e7>

Since there is only one query time range and hence one `interval` value for an entire dashboard, this will allow a per-query override as needed.

Once this gets merged and included in a new build of the openHistorian you can test this out to see if it improves your query performance for larger data windows.

---

<div class="post-metadata">

**Author:** ![ricardlira](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ricardlira/32/1314_2.png) [@ricardlira](http://discussions.gridprotectionalliance.org/u/ricardlira)\
**Post date:** [June 6, 2024, 12:45pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/8 "2024-06-06T12:45:56Z")

</div>

Thanks Ritchie, looking forward to test it in the next OH plugin version. Is the one we might get next week?

---

<div class="post-metadata">

**Author:** ![ritchiecarroll](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ritchiecarroll/32/2_2.png) [@ritchiecarroll](http://discussions.gridprotectionalliance.org/u/ritchiecarroll)\
**Post date:** [June 6, 2024, 2:16pm UTC](http://discussions.gridprotectionalliance.org/t/changing-grafana-query-options-max-data-points-based-on-a-dashboard-variable/1273/9 "2024-06-06T14:16:42Z")

</div>

I think next week is a reasonable time frame. Thanks!
