# Select sum from multiple measurements with regex

**URL:** <https://community.influxdata.com/t/select-sum-from-multiple-measurements-with-regex/13001>\
**Category:** Dashboards\
**Tags:** influxdb, grafana, query\
**Created:** [February 13, 2020, 9:05am UTC](https://community.influxdata.com/t/select-sum-from-multiple-measurements-with-regex/13001 "2020-02-13T09:05:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![romanl](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@romanl](https://community.influxdata.com/u/romanl)\
**Post date:** [February 13, 2020, 9:05am UTC](https://community.influxdata.com/t/select-sum-from-multiple-measurements-with-regex/13001/1 "2020-02-13T09:05:39Z")

</div>

Hello everyone,

currently, I am trying to query data over multiple measurements and visualize it with grafana.

The following works for now:

```auto
SELECT count("myField") FROM /^\d{4}$/ GROUP BY time(1w)

```

But this gives me a count for each measurement per week. Is it possible to combine all results?

I thought about something like this, but it is not working:

```auto
SELECT sum("count") FROM (SELECT count("myField") FROM /^\d{4}$/) GROUP BY time(1w)

```

Anyone got an idea what could solve my problem?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [February 14, 2020, 5:27pm UTC](https://community.influxdata.com/t/select-sum-from-multiple-measurements-with-regex/13001/2 "2020-02-14T17:27:21Z")

</div>

Hello @romanl,  
Welcome! I recommend using v1.7.6+ or v2.x so that you can have access to Flux and [join()](https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/built-in/transformations/join/) to perform [math across measurements](https://www.influxdata.com/blog/influxdb-how-to-do-joins-math-across-measurements/).

I believe it would look something like:

```auto
table1 = from(bucket: "default")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "disk")
  |> filter(fn: (r) => r._field == "free")

table2 = from(bucket: "default")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> filter(fn: (r) => r.cpu == "cpu-total" and r._field == "usage_system")

joined = join(tables: {disk: table1, cpu: table2}, on: ["_time"], method: "inner")
  |> count(column: "_value")

```
