Writting calculated data back into Bucket with a task

I have been able to get data from different buckets, do some math on them and then display the results in the data explorer. However I cannot figure out how to write this calculated data back to a bucket.

What do I need to do with to(bucket: ) to work and not get the error ```
no column with label _measurement exists ?



   >      Produced = from(bucket: "Envoy")
>        |> range(start: v.timeRangeStart)
>        |> filter(fn: (r) => r._measurement == "wattsNow" )
>        |> fill(column: "_value", usePrevious: true)
>        |> aggregateWindow(every: 30s, fn: mean)
>        |> keep(columns: ["_value", "_time"])
>        
>        
>        
>     Injected = from(bucket: "linky2")
>        |> range(start: v.timeRangeStart)
>        |> filter(fn: (r) => r._measurement == "SINSTI" )
>        |> fill(column: "_value", usePrevious: true)
>        |> aggregateWindow(every: 30s, fn: mean)
>        |> keep(columns: ["_value", "_time"])
>       
>        
>        
>     Consumed = from(bucket: "linky2")
>        |> range(start: v.timeRangeStart)
>        |> filter(fn: (r) => r._measurement == "SINSTS" )
>        |> fill(column: "_value", usePrevious: true)
>        |> aggregateWindow(every: 30s, fn: mean)
>        |> keep(columns: ["_value", "_time"])
>        
>        
>        
>     first_join = join(tables: {Produced: Produced, Injected: Injected}, on: ["_time"])
>         |> fill(column: "_value_Produced", usePrevious: true)
>        |>fill(column: "_value_Produced", value: 1.0)
>         |> fill(column: "_value_Injected",usePrevious: true)
>        |>fill(column: "_value_Injected", value: 1.0)
>        
> 
>     second_join = join(tables: {first_join: first_join, Consumed: Consumed}, on: ["_time"])
>        |>fill(column: "_value", usePrevious: true)
>        |>fill(column: "_value", value: 1.0)
>        |>map(fn: (r) => ({_time: r._time, _Consumed: r._value, _Produced:r._value_Produced, _Injected:r._value_Injected}))
>        
>      
>      final = second_join
>     	|>map (fn: (r) => ({_time:r._time, Consumed:r._Consumed, Produced:r._Produced, Injected:r._Injected}))
>     	|> keep(columns:["_time", "Consumed","Produced", "Injected"])
>       |> toInt()
> 
>     calc2t = final	
>     	|>map (fn: (r) => ({"_time":r._time, "test":(r.Produced - r.Consumed)}))
>     	|> yield(name: "mean")