pivot() collects unique values stored vertically (column-wise) and aligns them
horizontally (row-wise) into logical sets.
The group key of the resulting table is the same as the input tables,
excluding columns found in the
These columns are not part of the resulting output table and are dropped from
the group key.
Every input row should have a 1:1 mapping to a particular row and column
combination in the output table. Row and column combinations are determined
columnKey parameters. In cases where more than one
value is identified for the same row and 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
rowKeyunioned with the group key, but excluding the columns indicated by the
- A new column is added to the set of columns for each unique value
identified by the
- The label of a new column is the concatenation of the values of
_as a separator. If the value is null, “null” is used.
- A new row is created for each unique value identified by the
- 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
valueColumnat the row identified by the
rowKeyvalues and the new column’s label. If no value is found, the value is set to
- Any column that is not part of the group key or not specified in the
valueColumnparameters is dropped.
Function type signature
(<-tables: stream[A], columnKey: [string], rowKey: [string], valueColumn: string) => stream[B] where A: Record, B: Record
(Required) Columns to use to uniquely identify an output row.
(Required) Columns to use to identify new output columns.
Column to use to populate the value of pivoted
Input data. Default is piped-forward data (
Align fields into rows based on time
data |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
Associate values to tags by time
import "sampledata" sampledata.int() |> pivot(rowKey: ["_time"], columnKey: ["tag"], valueColumn: "_value")
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.