# How to convert InfluQL to Flux with GROUP BY and WHERE

**URL:** <https://community.influxdata.com/t/how-to-convert-influql-to-flux-with-group-by-and-where/23438>\
**Category:** Fluxlang\
**Tags:** influxdb, query, flux\
**Created:** [January 19, 2022, 9:47am UTC](https://community.influxdata.com/t/how-to-convert-influql-to-flux-with-group-by-and-where/23438 "2022-01-19T09:47:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_van\_den\_Bogaart](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tom_van_den_bogaart/32/9268_2.png) [@Tom\_van\_den\_Bogaart](https://community.influxdata.com/u/Tom_van_den_Bogaart)\
**Post date:** [January 19, 2022, 9:47am UTC](https://community.influxdata.com/t/how-to-convert-influql-to-flux-with-group-by-and-where/23438/1 "2022-01-19T09:47:59Z")

</div>

I am making an IoT Dashboard where I want to visualize data from a machine. Now I want to make the step to Influx 2.0, but the new Flux language is different, and I cannot figure this problem out. In Grafana I have the following InfluxQL query:

```auto
SELECT sum("execution_duration") / sum("interval_duration") as "Availability" FROM "data-oee" WHERE $timeFilter GROUP BY time($time_interval)

```

Now I want to execute this query as a Flux query, I’ve made an query but it doesn’t give me the right results:

```auto
from(bucket: "Dashboard")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "oee-data")
  |> filter(fn: (r) => r["machine"] == "ilv")
  |> filter(fn: (r) => r["_field"] == "no_production_duration" or r["_field"] == "production_duration")
  |> cumulativeSum(columns: ["_field"])
  |> aggregateWindow(every: 1h, fn: sum, createEmpty: false)
  |> yield(name: "sum")

```

I want to sum all the values that have the \_field name “execution\_duration” and divide it by the sum of all the values from the field name “interval\_duration” by doing this I get a list of timestamps with some kind of availability value that I want to visualize.

The data in my InfluxDB:

 ![notraw](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a0d6111b954ee660667936d3ed9cbdcf4cda74d6.png)

I hope you guys know how to fix this…

---

<div class="post-metadata">

**Author:** ![grant1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/grant1/32/15107_2.png) [@grant1](https://community.influxdata.com/u/grant1)\
**Post date:** [January 20, 2022, 2:04pm UTC](https://community.influxdata.com/t/how-to-convert-influql-to-flux-with-group-by-and-where/23438/2 "2022-01-20T14:04:34Z")

</div>

Hi Tom. I am sure there is a way to write a query to do what you want, but another approach might be to just make 2 queries (one for the sum of “execution\_duration” and another for the sum of “interval\_duration”) and then do a Transformation in Grafana:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/ad5271b978af03e0bf9b7081ffedd287e3ea07c7.png)
