How to Multiply the result with Constant ( flux query)

I need to multiply the result of the below program with a constant ( 0.1135). How to do that? Thanks in Advance!

from(bucket: “ABC”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “DentMeter”)
|> filter(fn: (r) => r[“_field”] == “BRPumpsKWH” or r[“_field”] == “ChillersKWH” or r[“_field”] == “HousePanelKWH”)
|> spread()
|> group()
|> sum()

Hi @Bharath
Perhaps you can make use of the map() function:

from(bucket: “ABC”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “DentMeter”)
|> filter(fn: (r) => r[“_field”] == “BRPumpsKWH” or r[“_field”] == “ChillersKWH” or r[“_field”] == “HousePanelKWH”)
|> spread()
|> group()
|> sum()
 |> map(fn: (r) => ({ r with _value: r._value * 0.1135 }))
1 Like

Thank you so much Jay. It is working and very helpful.

Hey Jay When I use the above code, there is an issue because of the use case. if I use the spread(), It was taking the last value and subtracts the first value.

But the use case is sometimes the Meter Reading will reset to Zero due to maintenance or power issue. In that case, the Spread() function will give the wrong value.

So I am trying to totalize the values, Like finding only the Positive difference between two consecutive records and totalizing it to find the correct consumption.

Is there any function for this? Thanks!

Bharath

@Anaisdg do you have any ideas on how we can achieve this one?

With energy meters and the kwh reading the internal registry will always rollover at a certain point. There are two typical ways you could use to avoid this rollover issue.

  • Certain top level meters have a register for block energy, which will give you the energy consumed in 15 minute periods.

  • If you’re reading the meter every 15 minutes for example, you could also take the power register (kw) and multiply it by (15[min] / 60[min]), and the you would only need to sum the records.

  • You could also read the last energy value, substract it from the current value, and store what would be the consumed energy in that period. When the result of the substraction is negative, apply the difference between the rollover value and the current value to always get the energy consumed in the period.