Use values to calculate a new column

This example uses NOAA water sample data.

This example converts temperature from Fahrenheit to Celsius and maps the Celsius value to a new celsius column.

The following query: - Uses filter() to filter the average_temperature measurement. - Uses map() to create a new column calculated from existing values in each row.

  1. from(bucket: "noaa")
  2. |> filter(fn: (r) => r._measurement == "average_temperature")
  3. |> map(fn: (r) => ({r with
  4. celsius: ((r._value - 32.0) * 5.0 / 9.0)
  5. })
  6. )

Example results

_start_stop_field_measurementlocation_time_valuecelsius
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:00:00Z8227.78
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:06:00Z7322.78
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:12:00Z8630.00
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:18:00Z8931.67
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:24:00Z7725.00
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:30:00Z7021.11
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:36:00Z8428.89
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:42:00Z7624.44
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:48:00Z8529.44
1920-03-05T22:10:01Z2020-03-05T22:10:01Zdegreesaverage_temperaturecoyote_creek2019-08-17T00:54:00Z8026.67
••••••••••••••••••••••••

queries