Multiple calculations

Hello,
I’m looking to calculate the sum of two fields and then perform a calculation on them to workout the difference.

In the code below I am calculating the sum of “cost” and the sum of “new_value” which works fine. However, I now want to calculate “new_value - cost”

I thought about using pivot() but the produced tables below (original and new_value) don’t have any _time columns.

original = from(bucket: "inventory")
  |> range(start: 1970-08-28T22:00:00Z)
  |> filter(fn: (r) => r["_field"] == "cost")
  |> last()
  |> group(columns: ["_field"])
  |> sum(column: "_value")
  |> map(fn: (r) => ({ r with _value: r._value - 1500.01 }))

new_value = from(bucket: "inventory")
  |> range(start: v.timeRangeStart)
  |> filter(fn: (r) => r["_field"] == "new_value")
  |> last()
  |> group(columns: ["_field"])
  |> sum(column: "_value")