Documentation

Operate on columns

Use the following common queries to operate on columns:

These examples use NOAA water sample data.

Find and count unique values in a column

Find and count the number of unique values in a specified column. The following examples find and count unique locations where data was collected.

Find unique values

This query:

  • Uses group() to ungroup data and return results in a single table.
  • Uses keep() and unique() to return unique values in the specified column.
from(bucket: "noaa")
    |> range(start: -30d)
    |> group()
    |> keep(columns: ["location"])
    |> unique(column: "location")

Example results

location
coyote_creek
santa_monica

Count unique values

This query:

  • Uses group() to ungroup data and return results in a single table.
  • Uses keep(), unique(), and then count() to count the number of unique values.
from(bucket: "noaa")
    |> group()
    |> unique(column: "location")
    |> count(column: "location")

Example results

location
2

Recalculate the _values column

To recalculate the _value column, use the with operator in map() to overwrite the existing _value column.

The following query:

  • Uses filter() to filter the average_temperature measurement.
  • Uses map() to convert Fahrenheit temperature values into Celsius.

from(bucket: "noaa")
    |> filter(fn: (r) => r._measurement == "average_temperature")
    |> range(start: -30d)
    |> map(fn: (r) => ({r with _value: (float(v: r._value) - 32.0) * 5.0 / 9.0} ))
_field_measurement_start_stop_timelocation_value
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:00:00Zcoyote_creek27.77777777777778
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:06:00Zcoyote_creek22.77777777777778
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:12:00Zcoyote_creek30
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:18:00Zcoyote_creek31.666666666666668
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:24:00Zcoyote_creek25
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:30:00Zcoyote_creek21.11111111111111
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:36:00Zcoyote_creek28.88888888888889
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:42:00Zcoyote_creek24.444444444444443
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:48:00Zcoyote_creek29.444444444444443
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T00:54:00Zcoyote_creek26.666666666666668
degreesaverage_temperature1920-03-05T22:10:01Z2020-03-05T22:10:01Z2019-08-17T01:00:00Zcoyote_creek21.11111111111111
•••••••••••••••••••••

Calculate a new column

To use values in a row to calculate and add a new column, use map(). This example below 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.
from(bucket: "noaa")
    |> filter(fn: (r) => r._measurement == "average_temperature")
    |> range(start: -30d)
    |> map(fn: (r) => ({r with celsius: (r._value - 32.0) * 5.0 / 9.0}))

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
••••••••••••••••••••••••

Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.

InfluxDB Cloud powered by TSM