pivot() function

The pivot() function collects values stored vertically (column-wise) in a table and aligns them horizontally (row-wise) into logical sets.

pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")

The group key of the resulting table is the same as the input tables, excluding columns found in the columnKey and valueColumn parameters. This is because these columns are not part of the resulting output table.

Every input row should have a 1:1 mapping to a particular row + column in the output table, determined by its values for the rowKey and columnKey parameters. In cases where more than one value is identified for the same row + column pair, the last value encountered in the set of table rows is used as the result.

The output is constructed as follows:

  • The set of columns for the new table is the rowKey unioned with the group key, but excluding the columns indicated by the columnKey and the valueColumn.
  • A new column is added to the set of columns for each unique value identified in the input by the columnKey parameter.
  • The label of a new column is the concatenation of the values of columnKey using _ as a separator. If the value is null, "null" is used.
  • A new row is created for each unique value identified in the input by the rowKey parameter.
  • For each new row, values for group key columns stay the same, while values for new columns are determined from the input tables by the value in valueColumn at the row identified by the rowKey values and the new column’s label. If no value is found, the value is set to null.
  • Any column that is not part of the group key or not specified in the rowKey, columnKey and valueColumn parameters is dropped.



List of columns used to uniquely identify a row for the output.


List of columns used to pivot values onto each row identified by the rowKey.


Column that contains the value to be moved around the pivot.


Input data. Default is piped-forward data (<-).


Align fields within each measurement that have the same timestamp

    |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

View example input and output

Align fields and measurements that have the same timestamp

Note the effects of:
  • Having null values in some columnKey values.
  • Having more values for the same rowKey and columnKey value (the 11th row overrides the 10th, and so does the 15th with the 14th).
    |> pivot(rowKey: ["_time"], columnKey: ["_measurement", "_field"], valueColumn: "_value")

View example input and output

Align values for each tag

The following example uses data provided by the sampledata package to show how pivot() transforms data.

import "sampledata"
    |> pivot(rowKey: ["_time"], columnKey: ["tag"], valueColumn: "_value")

View input and output

Was this page helpful?

Thank you for your feedback!

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.