docs-v2/content/v2.0/reference/flux/stdlib/influxdb-v1/fieldsascols.md

1.2 KiB

title description aliases menu weight
v1.fieldsAsCols() function The v1.fieldsAsCols() function is pivots a table and automatically aligns fields within each input table that have the same timestamp.
/v2.0/reference/flux/functions/inputs/fromrows
/v2.0/reference/flux/functions/transformations/influxfieldsascols
/v2.0/reference/flux/functions/influxdb-v1/fieldsascols/
v2_0_ref
name parent
v1.fieldsAsCols InfluxDB v1
301

The v1.fieldsAsCols() function is a special application of the pivot() function that automatically aligns fields within each input table that have the same timestamp.

Function type: Transformation

import "influxdata/influxdb/v1"

v1.fieldsAsCols()

Examples

import "influxdata/influxdb/v1"

from(bucket:"example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> v1.fieldsAsCols()
  |> keep(columns: ["_time", "cpu", "usage_idle", "usage_user"])

Function definition

fieldsAsCols = (tables=<-) =>
  tables
    |> pivot(
      rowKey:["_time"],
      columnKey: ["_field"],
      valueColumn: "_value"
    )

Used functions: pivot()