QL to Flux in a query

Please could someone help me im tring to convert a Query from QL to flux and cant seem to get it right



it is for it is taking a value and calculating to differance every hour to put in a bar graph.

thank in advance Tommy

Have you tried building the Flux query in Influx Data Explorer? I usually have good success there and then copy/paste the query to Grafana.

Hi grant, yes ive done that in the notebook but i just cant seem to make the numbers match to to old QL
from(bucket: “LawtonYarns”) |> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> filter(fn: (r) => r["_measurement"] == “EM3_Electrical_Workshop”)

|> filter(fn: (r) => r["_field"] == “Total_Power1”)

|>difference(nonNegative: false, columns: ["_value"])

|> aggregateWindow(every:1h, fn: last, createEmpty: false)

When you build the above Flux query in Influx Data Explorer, do you see any output on the graph?

dummy example:


think im just missing something with the time its working but the valuse are not the same as the old one im trying to get the differance between every hour of the 4 incrumenting values. its for kwh from a power meter measureing 3 phase and total.

What about in Influx Data Explorer? The URL would be http://<<your server>>:8086

That is where I will often build and test the query before trying it in Grafana.


yes this is in query


this is the right figures see the kwh


and this is what im getting in flux the pattern is the same just the numbers are out ???


thanks for you help grant i think i got it using the derivative like in your example.

1 Like

another quick question how do i give the data an alias like in QL ?

You can use a Transformation to rename the data to something else. If you do not know how, search the forum with my name and the word transformation and influx and it should show up someplace.

This might be a useful resource in the future: TL;DR InfluxDB Tech Tips: Converting InfluxQL Queries to Flux Queries