Flux query with multiple data within chronograf

I’m new to influx (but absolutely love it so far), but am struggling to execute a query selecting multiple data (and hence multiple tables - I think - I’m not sure as I’m still learning).

I have an influx database where I’m collecting data from different sensors. Each sensor has a tag which is the type of sensor (e.g. temperature or light) and I’d like to display data from multiple sensors in chronograf. This works fine, and I get multiple graphs displayed, but unfortunately the scales are widely different, so I’d like to shrink the scale of one of them.

I’ve tried doing this with the following query:

from(bucket: "mydb")
|> range(start: -12h)
|> filter(fn: (r) =>  (r.sensor == “temp” or r.sensor == “light”))
|> map(fn: (r) => ({
  r with
    _value:
    //r._value / 100.0 // replacing the below with this line works
    if r.sensor == "light" then r._value / 100.0
  })
)

Unfortunately this displays nothing and there is no error message (on a related point, where would this be displayed in chronograf?).

If I comment the line “if r.sensor == “light” then r._value / 100.0” and replace it with “r._value / 100.0” this works, but obviously scales all the values by the same quantity, which isn’t what I want.

If I run the query with “if r.sensor == “light” then r._value / 100.0” on the influxdb command-line, I get the error: “loc 5:5-12:1: expected RPAREN, got EOF”. It therefore looks like the issue is with the syntax, but I’m not sure how to fix that.

@linucks Your if statement needs an else to provide a default value when the r.sensor == "light" predicate returns false.

from(bucket: "mydb")
|> range(start: -12h)
|> filter(fn: (r) =>  r.sensor == "temp" or r.sensor == "light" )
|> map(fn: (r) => ({
  r with
    _value: if r.sensor == "light" then r._value / 100.0 else r._value
  })
)

Brilliant - works perfectly! Thanks @scott

No problem. Happy to help!