Changing Y-axis from 4-20 >> 0-20 by offset and scaling conversion

I have data from 4-20 but I’d like to re-scale that and show it as 0-20. So effectively, I would first subtract 4, then divide by 16 and multiply by 20 (offset and scaling).
Can this be done somehow? I’m thinking I should probably convert the (sensor) data before I graph it.

I’m (very) new to Grafana so any hints would be very much appreciated.

Either will work.

Rescale / convert the values in your back-end data store before Grafana ever
gets to see it, or if you prefer, do precisely the calculation you outline
above in the query of your Grafana panel.

If you’re not sure how to do that, cut and paste the current query (as shown
in the Query Editor) into a reply here, and we can help you adjust it


Hope I’m doing this right… here’s what I think is what you are asking for… (I replaced my moreID for …'s; hope that’s fine)

SELECT “value” FROM “I” WHERE (“mote” = ‘…’) AND $timeFilter GROUP BY “location”

Okay, so change that to:

SELECT (“value”-4)*1.25 FROM “I” WHERE (“mote” = ‘…’) AND $timeFilter GROUP
BY “location”

Let us know how you get on :slight_smile:


error parsing query: found “, expected identifier, string, number, bool at line 1, char 9

If I make “value”-4 that works. Not sure how to save that however as if I leave the editor it’s gone

Firstly try removing the quotation marks to eliminate the error you reported

SELECT (value-4)*1.25 FROM “I” WHERE (“mote” = ‘…’) AND $timeFilter GROUP
BY “location”

Secondly, what do you mean by “leave the editor”?

If you adjust a query manually, it’s important not to toggle back to the
automatic mode - just leave it as it is and it’ll stay that way.

Just use the “Go back” arrow in the top left corner and you’ll see the result
of the query in the main dashboard again.


Thanks Anthony,

That works; still strange that if I toggle the edit mode all reverts back. Can’t I ‘save’ this change then?
2020 Feb 25 205956-Window

There is no “save” mechanism in Grafana (which I also find somewhat odd).

Whatever is the last thing you leave in the editor (either in automatic mode
or in manual mode) is what lasts.

And yes, the way that toggling back to automatic immediately destroys (with no
way of going back) your manual edits I also find irritating.

My solution to all of this was to learn how to create panels and dashboards
using JSON and then uploading them for auto-provisioning.

Hope that helps…


What does the ‘Save Dashboard’ button do then?

That saves the dashboard layout.

It doesn’t save the queries in each panel of the dashboard, beyond whatever
state they were last left in.

So, yes, you can save a dashoard, but no, you can’t explicit;y save a panel -
it just remains in whatever state you last left it.


That doesn’t seem to agree with what I am seeing. I edited a query and then logged out without saving the dashboard. I got a warning from the browser that I was leaving without saving which I ok’d. When I then view the dashboard again the query edit has been reverted.

[Edit] In addition, if you view the JSON for a panel (Click on the panel title > More… > Panel JSON) then that can be seen to include the query. I assumed that when a dashboard is saved it includes the panel JSON, so would include the query details.

I believe you’re saying the same thing as I am.

If you edit a panel, there is no explicit “save” function for it.

There is a save function for a dashboard, and that saves the current state
of all its component panels.

So, if you edit a panel, and then exit the dashboard without saving it, you
lose the edit to the panel, because the dashboard (and its panels) remains in
the previously saved state.

There just isn’t anything you need to do to a panel to save its edits. You
can modify three panels and they all get saved when you save the dashboard,
for example.


OK, so if I understand correctly you mean there isn’t a Save mechanism per panel, you can only save all the panels (with their queries) by saving the whole dashboard.
If so then the answer to @erikjan59’s question about a panel query " Can’t I ‘save’ this change then?" then the answer is yes you save it by clicking the Save Dashboard button at the top, which saves the whole dashboard including that change.
I agree that there should be at least a warning if one tries to go back to the simpler edit mode (which cannot support all the subtleties of a manually entered query) if the full query cannot be represented in the simpler view. I have made that mistake myself several times.

I tested: the query changes were active and I saved the dashboards. The moment I removed the query editor and brought it back, the original query (without any customizations I had made) returned.
Seems to me that one cannot save edits… VERY strange and illogical if you ask me: why would a system allow a query to be edited and thus changed and KEEP these changes unless the edit window is closed?

Do you mean you switched from text edit mode back to the mode that allows you to enter the fields and so on without using the query language? If so then (as has been mentioned several times above) if you are using features of the query language that cannot be shown in the simpler view then you must not switch out of text edit mode or your query will be lost. It is not an Edit Window, it is a more sophisticated way of entering the query. You must decide which mode you want for each query and not switch back to the simple view if you need the full Text Edit view. Make the changes in the Text Edit view, save the dashboard, and leave that query in that mode. It will still be there next time you look at the configuration for that panel.
Also as I said earlier I think it is most unfortunate that it does not warn you when switching back and losing information.

Yes. You are correct, that is how it appears to work. With all due respect: not logical (even if I would be warned). But now I know, I hope that I’ll not forget…
Imagine you changed the query into something quite fancy and special to fit your purpose… one click and it’s all gone (I’ve been programming for 40 yrs or so but never seen something similar).
Anyway, thanks to all for helping and the clarifications, it is very much appreciated!

Only if you haven’t saved the dashboard since you setup the query (or you save it after you click). If you accidentally click then force a refresh of the page and it should go back to the previous saved value. If not then close the browser window and reopen it.
However I do agree that the behaviour is a long way from ideal. I don’t know whether there it would be worth submitting an issue suggesting that there should at least be a warning.