# Simple Math with Flux

Hi,
Just having a play with Flux using InfluxDB v1.7.6 and can’t seam to get math to work

currently in Chronograf I have:

``````tbl_Pow_Wh = from(bucket: "dbDemo/1year")
|> range(start: dashboardTime)
|> filter(fn: (r) =>
r._measurement == "Demo" and
r._field == "value" and
r.Signal == "Watt" and
r.Equipment == "Main Board"
)
|> aggregateWindow(every: 15m, fn: sum)
|> map(fn: (r) => r._value * 1000))
``````

and all I get is “[object Object]” in the data window. Without the map function I get data like:

#datatype string long dateTime:RFC3339 dateTime:RFC3339 dateTime:RFC3339 string string string string string double
#group FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE FALSE
#default _result
result table _start _stop _time Device Equipment Signal _field _measurement _value
0 2019-05-09T03:42:05.140537091Z 2019-05-10T03:42:05.140537091Z 2019-05-09T03:45:00Z House Load Main Board Watt value Demo 432.6
0 2019-05-09T03:42:05.140537091Z 2019-05-10T03:42:05.140537091Z 2019-05-09T04:00:00Z House Load Main Board Watt value Demo 436.1
0 2019-05-09T03:42:05.140537091Z 2019-05-10T03:42:05.140537091Z 2019-05-09T04:15:00Z House Load Main Board Watt value Demo 439.9

any help would be appreciated, thanks.

Hi @Yendor welcome ,

Is the result without the map function ok ?
In the map function you have 2 )) at the end ,
You need only 1 )

Thanks @MarcV,
Yes the query returns data without the map function correctly.

I was tying a few combinations

``````|> map(fn: (r) => (r._value * 1000))
------------------------------------
|> map(fn: (r) => r._value * 1000)
``````

and left a typo in, even with the typo fixed I still get a error of

``````Error: type error 0:0-0:0: invalid record access "_value":int != float
``````

after tying the following combinations finally got one to work

``````|> toFloat()
|> aggregateWindow(every: 15m, fn: sum)
|> map(fn: (r) => r._value * 1000)  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => float(v: r._value) * float(v: 1000))  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => float(v: r._value) * 1000.0)  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => float(v: r._value) * 1000.00)  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => r._value *  float(v: 1000))  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => r._value *  1000.0)  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => r._value *  1000.00)  # Error: Internal Server Error
---------------------------------------
|> map(fn: (r) => ({_value: (r._value * 1000))})  # Error: type error 0:0-0:0: invalid record access "_value":int != float
``````

and the working one

``````|> map(fn: (r) => ({_value: (r._value * 1000.00))})
``````

then going back to

``````|> map(fn: (r) => float(v: r._value) * 1000.0)
---------------------------------------
|> map(fn: (r) => float(v: r._value) * 1000.00)
``````

both where working, got me stumped. I guest its still a beta so there are some bugs.

i was fighting with map few days with influxdb-1.7.7/chronograf-1.7.12. Finally on
influxdb-1.7.8/chronograf-1.7.14 the following construction works:

`|> map(fn: (r) => ({_time: r._time, card: r.card, _value: r._value * 8.0 / 1073741824.0}))`

this was to convert bytes to gigabits. Dramatically depends on version so far.