Dropping initial tables after pivot

Hi all,

I am trying to get started with Flux (coming from influxQL), and having a hard time translating this simple influxQL query:

SELECT sum("east") - sum(eait) as "Soutirage / Injection", sum("pv") as "Prod PV" FROM $iota.autogen.energy WHERE  $timeFilter GROUP BY time($kWh_interval,$tz_offset) fill(null)

Going through the docs I cam up with the following: map() generates the table I need in Grafana, however the initial 3 tables are still in the stream… is there any way I can get rid of them?
Setting _measurement = pv_summary and calling filter at the end is the best I could think of, but that seems to have no effect (I am using Explore Data in the Influxdb Web UI, Table view):

from(bucket: "iota-autogen")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "energy")
  |> filter(fn: (r) => r["_field"] == "pv" or r["_field"] == "east" or r["_field"] == "eait")
  |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({_time: r._time, _measurement: "pv_summary", soutirage_injection: r.east - r.eait, pv: r.pv}))
  |> filter(fn: (r) => r["_measurement"] == "pv_summary")

As a side question, is there really no way to obtain the pivoted table directly without having to call pivot, knowing that those fields all come from a single InfluxDB data point?

Solved, silly UI mistake, when defining multiple queries in the Web UI “Submit” returns the results from all queries, not just the one being edited.

This is what I eventually came up with, I will need a second query for the “pv” since apparently a) aggregateWindow can only aggregate one column and b) the only “unpivot” I find is experimental

from(bucket: “iota-autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “energy”)
|> filter(fn: (r) => r[“_field”] == “pv” or r[“_field”] == “east” or r[“_field”] == “eait”)
|> drop(columns: [“device”])
|> schema.fieldsAsCols()
|> map(fn: (r) => ({r with soutirage_injection: r.east - r.eait}))
|> drop(columns: [“eait”, “east”])
|> aggregateWindow(every: ${kWh_interval}, fn: sum, column: “soutirage_injection” )

Comparing with InfluxQL I can’t say I completely sold on Flux yet…