What is the correct syntax for this custom flux function call?

I’m trying to convert part of a working flux script to a custom function but keep getting syntax errors.

When executing the following code I get:

 error @14:1-14:7: missing required argument tables
data = from(bucket: "e-counters")
  |> range(start: 2022-02-01)
  |> filter(fn: (r) => r["_measurement"] == "electricity")
  |> filter(fn: (r) => r["agg_type"] == "last24h")

days = (tables=<-) => tables
  |> filter(fn: (r) => r["_field"] == "fT1")
  |> aggregateWindow(every: 1d, fn: count, createEmpty: false)
  |> count(column: "_value")
  |> map(fn: (r) => ({r with elapsed_days: float(v: r._value)}))
  |> keep(columns: ["elapsed_days", "_stop"])
  |> yield(name: "elapsed_days")

days()

When I change the last line into:

|> days()

I get:

 error @14:4-14:8: undefined identifier days

What do I need to change?

data
  |> days()

That did it; thank you so much!

1 Like