# How can I combine two different measurements?

**URL:** <https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936>\
**Category:** Telegraf\
**Tags:** influxdb\
**Created:** [October 8, 2018, 9:52am UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936 "2018-10-08T09:52:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardoatsouza](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ricardoatsouza/32/2194_2.png) [@ricardoatsouza](https://community.influxdata.com/u/ricardoatsouza)\
**Post date:** [October 8, 2018, 9:52am UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/1 "2018-10-08T09:52:50Z")

</div>

I am trying to achieve something that seems simple and, I would guess, possible in InfluxDB.

I have two measurements (both counters): MessagesReceived and MessagesProduced. What I want is to calculate the ratio in between produced and received. So I am looking for a query that looks like this:

`select A.value / B.value from MessagesProduced as A, MessagesReceived as B`

Naively speaking, seems to be simple and straightforward. But I couldn’t find a way to make it work with InfluxDB. So, my questions are:

1. Is it possible to do something like this in InfluxDB?
2. If not, is there a workaround?
3. If yes, how?

Thanks

---

<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:** [October 8, 2018, 6:42pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/2 "2018-10-08T18:42:59Z")

</div>

Hello @ricardoatsouza,

I was able to do this with this query `SELECT "usage_guest"/"usage_system" FROM "telegraf"."autogen"."cpu" limit 10` from the default telegraf database which gathers metrics from my local machine.

Could you maybe share your schema and exact query, if that syntax doesn’t work for you?

Best,

Anais

---

<div class="post-metadata">

**Author:** ![ricardoatsouza](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ricardoatsouza/32/2194_2.png) [@ricardoatsouza](https://community.influxdata.com/u/ricardoatsouza)\
**Post date:** [October 9, 2018, 8:41am UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/3 "2018-10-09T08:41:58Z")

</div>

Hi @Anaisdg,  
Thanks for the answer.

In your example, you are making the division of two fields from the same measurement. The problem is that I want to do it with the value of two different measurements: MessagesProduces and MessagesReceived. And, to make it more fun, they have both a field named `value`.

I know I can select both values with this query:

`select value from MessagesReceived, MessagesProduced`

But I cannot get what I expect running:

`select value/value from MessagesReceived, MessagesProduced`

The reason of why it doesn’t work is because InfluxDB doesn’t know to whom `value` belongs to, which is very clear to me. So, I would expect influxDB to able to make references to them in the `select` clause, like:

`select MessagesProduced.value/MessagesReceived.value from MessagesReceived, MessagesProduced`

Or to have aliases, like:

`select A.value/B.value from MessagesReceived as B, MessagesProduced as A`

This nails down the question to: is it possible to make references in the `select` clause to different measurements in the `from` clause? Even if they have the same field name?

Thanks

Ricardo

---

<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:** [October 9, 2018, 7:45pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/4 "2018-10-09T19:45:51Z")

</div>

Hello @ricardoatsouza,

Unfortunately, there is no way to perform cross-measurement math or grouping with influxql. All data must be under a single measurement to query it together. This [issue has been raised](https://github.com/influxdata/influxdb/issues/3552). With [Flux](https://www.influxdata.com/blog/announcing-ifql-a-new-query-language-and-engine-for-influxdb/) you will be able to do this.

Best,

Anais

---

<div class="post-metadata">

**Author:** ![samaust](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/samaust/32/867_2.png) [@samaust](https://community.influxdata.com/u/samaust)\
**Post date:** [October 9, 2018, 11:55pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/5 "2018-10-09T23:55:14Z")

</div>

If you can change your series format, here’s a suggestion.

measurement : Messages  
fields :

- Produced
- Received

So the query becomes

`SELECT "Produced" / "Received" FROM Messages`

---

<div class="post-metadata">

**Author:** ![ricardoatsouza](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ricardoatsouza/32/2194_2.png) [@ricardoatsouza](https://community.influxdata.com/u/ricardoatsouza)\
**Post date:** [October 10, 2018, 8:54am UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/6 "2018-10-10T08:54:51Z")

</div>

Hi @samaust,

That’s what I am considering doing.  
The problem is that I am using a Golang library statsd ([GitHub - alexcesaro/statsd: An efficient Statsd Go client.](https://github.com/alexcesaro/statsd)) that doesn’t give the option to create more fields under the same measurement (or I am really missing something). As a result, every measurement goes under the one field `value` in influxDB.

@Anaisdg I will give a check on Flux. But, either way, the feature cross-measurement math sounds like something not so difficult to do. Are there any plans in the pipeline to include it in InfluxDB?

Thanks

Ricardo

---

<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:** [October 10, 2018, 2:11pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/7 "2018-10-10T14:11:29Z")

</div>

Hi @ricardoatsouza,

Yes, Flux is our new query engine and it will allow you to perform cross-measurement math.

Best,

Anais

---

<div class="post-metadata">

**Author:** ![ravi1050](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@ravi1050](https://community.influxdata.com/u/ravi1050)\
**Post date:** [May 2, 2019, 9:42pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/8 "2019-05-02T21:42:57Z")

</div>

If you cannot change your measurement schema, you can Continuous Query and downsample your records to achieve this. ie.,  
Select sum(value) as value\_produced INTO Messages from MessagesReceived where …  
Select sum(value) as value\_consumed INTO Messages from MessagesProduced where …

Now, select value\_produced/value\_consumed from Messages where…

---

<div class="post-metadata">

**Author:** ![thomcrowe](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/thomcrowe/32/2580_2.png) [@thomcrowe](https://community.influxdata.com/u/thomcrowe)\
**Post date:** [May 3, 2019, 3:37pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/9 "2019-05-03T15:37:36Z")

</div>

Welcome to InfluxData Community — **thanks for contributing!**

---

<div class="post-metadata">

**Author:** ![amanmishra1321](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@amanmishra1321](https://community.influxdata.com/u/amanmishra1321)\
**Post date:** [October 13, 2020, 1:09pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/10 "2020-10-13T13:09:58Z")

</div>

Hey,I am getting the same problem, I want to subtract the time of different measurement but the thing is we cannot add 3 time column in a measurement and there is no JOIN clause in InfluxQL. Now I want to write queries in Flux but it is not supporting it in 1.8 version of Influxdb whereas there is no any download link available for windows of InfluxDB2.0 version.I am using grafana latest stable version(7.2.1).

---

<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:** [April 14, 2021, 5:46pm UTC](https://community.influxdata.com/t/how-can-i-combine-two-different-measurements/6936/11 "2021-04-14T17:46:12Z")

</div>

Hello @amanmishra1321,  
Are you not able to enable Flux in 1.8?

> **[Enable Flux | InfluxDB OSS 1.8 Documentation](https://docs.influxdata.com/influxdb/v1.8/flux/installation/)**
>
> Instructions for enabling Flux in your InfluxDB configuration.
