Filter values in one field based on value of another field

Hello,

I am new to Flux and am using Influxdb to log my solar installation.

My inverter has the option to source power from two sources: Batteries or a back up generator.

I collect the power output every 5 minutes (Apparent power which I integrate to give me power consumed in KWh). The output could be from either my batteries or generator. Never both at the same time.

This is my flux query to calculate total power:

import "date"
today = date.truncate(t: now(), unit: 1d)
from(bucket: "plantA")  
  |> range(start: today)
  |> filter(fn: (r) => r["_measurement"] == "A001")
  |> filter(fn: (r) => r["_field"] == "ac_output_apparent_power")
  |> filter(fn: (r) => r["command"] == "QPGS1" or r["command"] == "QPGS2" or r["command"] == "QPGS3")
  |> aggregateWindow(
    every: 1h,
    fn: (tables=<-, column) =>
      tables
        |> integral(unit: 1h)
        |> map(fn: (r) => ({ r with _value: r._value / 1000.0})))
  |> aggregateWindow(fn: sum, every: 1d)

I also log ,every 5 minutes ,whether am using generator or not.

|> filter(fn: (r) => r["_measurement"] == "A001")
|> filter(fn: (r) => r["_field"] == "is_gen_off)

The challenge I am facing is how to determine the share of the total output from generator versus batteries?

Is it possible on Flux to add a filter to my total output query such that I can determine total power consumed whilst "is_gen_off has value 0? Essentially add a filter based on a field value.

Thanks

Duncan

Absolutely,
You an use conditional filtering
https://docs.influxdata.com/influxdb/v2.0/query-data/flux/conditional-logic/#conditionally-transform-column-values-with-map
lmk if you need help implementing this