Combine two Rows

@scott the range() wasn’t the problem. There was some kind of problem with the way I tried to access the first value within the column I extracted. This worked for me:

nWorkplaces = from(bucket: "plcview_4/autogen")
  |> range(start: 2021-01-29T00:00:00.000Z, stop: now())
  |> filter(fn: (r) => r._measurement == "FAULT_LASER")
  |> group()
  |> distinct(column: "workplace")
  |> count()
  |> tableFind(fn: (key) => true)
  |> getColumn(column: "_value")

and then later I could use this colum and extract the value in the calculation:

mtbf = noFaultDurations
  |> reduce(
  	fn: (r, accumulator) => ({ 
    	totalNoFaultTime: r.duration + accumulator.totalNoFaultTime,
        nFaults: accumulator.nFaults + 1
    }),
    identity: { totalNoFaultTime: 0, nFaults: nWorkplaces[0] }
  )
  |> map(fn: (r) => ({ _value: r.totalNoFaultTime / r.nFaults }))
  |> yield(name: "mtbf")

@scott Do you know if it is possible to translate all of what I did here into TICKscript? I am trying to automate the calculation and have it calculate the script every day and store the result into another database with a different retention policy. Since I am using v1.8.4 I can’t use Flux tasks…

I created a separate topic for this issue: Translate Flux into TICK script