Calculate Percentage with Union

Hi,

Im trying to provide a single percentage figure in a dashboard that shows the Week on Week percentage change in two totals. Right now I’ve got the following query:

lastweek = from(bucket: v.bucket)
  |> range(start: -14d, stop: -7d)
  |> filter(fn: (r) => r["_measurement"] == "api_call")
  |> filter(fn: (r) => r["_field"] == "request_count")
  |> drop(columns: ["organisation", "organisation_id", "type", "project", "project_id"])
  |> sum()

thisweek = from(bucket: v.bucket)
  |> range(start: -7d, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "api_call")
  |> filter(fn: (r) => r["_field"] == "request_count")
  |> drop(columns: ["organisation", "organisation_id", "type", "project", "project_id"])
  |> sum()

union(tables: [lastweek, thisweek])

And this gives me two rows with the 2 weeks of totals, but I can’t figure out how to then create a percentage change of these 2 values.

My result table currently looks like the following:

Hi Were you able to solve this? I have the same challenge