Using constant to establish multiplication factor in influxdb1 query

I’m using grafana 7.5.7 using docker in Ubuntu 20.04 to track electricity spendings and comparing my current price with other providers, calculates from realtime power measurement.

I’d like to have price per kWh easily configurable because I have a number of panels that use this, currently as a hardcoded value.

I tried to use constant type variable but I do not know how to reference it on my query and I’ve not found any example like my use case.

One of the queries looks like thsi:

SELECT integral("consumo_total"::float) / 3600000.0 * 0.18339 + (4.6 * 38.84 / 365)
    SELECT mean("value") AS consumo_total FROM "CasaW" WHERE $timeFilter GROUP BY time(1m) fill(0)
GROUP BY time(24h,-2h) 

And I would like to make 0.18339, 4.6 and 38.84 to be configurable values.

May anybody point me to the right solution. Thanks

Hi @gmag11

Have you explored using the unit option in the standard field options?

Hi @gmag11 what did you try exactly? If you for example define a variable of type constant called var1, and set its value to 3600000.0, you should then be able to use it in your query like

SELECT integral("consumo_total"::float) / $var1 * ...

In other words, you reference constant variable in the same way as variables of other types. Hope that helps?

EDIT: By the way, if you want the variable to show up at the top of the dashboard and be editable by the user, you can also use the “Text box” type.

Thank you. My problem was that I did not find how to call the variable as $var1.

TextBox trick is really nice.