# Mathematics with two variables

**URL:** <https://community.influxdata.com/t/mathematics-with-two-variables/29434>\
**Category:** Fluxlang\
**Tags:** telegraf, flux\
**Created:** [April 10, 2023, 3:50pm UTC](https://community.influxdata.com/t/mathematics-with-two-variables/29434 "2023-04-10T15:50:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio\_B](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/sergio_b/32/8227_2.png) [@Sergio\_B](https://community.influxdata.com/u/Sergio_B)\
**Post date:** [April 10, 2023, 3:50pm UTC](https://community.influxdata.com/t/mathematics-with-two-variables/29434/1 "2023-04-10T15:50:17Z")

</div>

Hi how can use the value from my first variable as a divisor in my second variable?

```auto
import "math"

latencyAverage = from(bucket:"telegraf")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop )
    |> filter(fn: (r) => r.host == "PRG-host")
    |> filter(fn: (r) => r._measurement == "nping_UDP")
    |> filter(fn: (r) => r["nping-dest"] == "qt-brazil")
    |> filter(fn: (r) => (r._field == "nping-avg"))
    |> mean()
    |> first()
    |> rename(columns: { "_value": "latencyAverage_values" })
   //|> yield(name:"latencyAverage")

jitter = from(bucket:"telegraf")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop )
    |> filter(fn: (r) => r.host == "PRG-host")
    |> filter(fn: (r) => r._measurement == "nping_UDP")
    |> filter(fn: (r) => r["nping-dest"] == "qt-brazil")
    |> filter(fn: (r) => (r._field == "nping-avg") or (r._field == "nping-pl_prct"), onEmpty: "keep")
    |> map(fn: (r) => ({r with latency_values: float(v:r._value)}))
    |> map(fn: (r) => ({r with packetLoss_values: float(v:r["nping-pl_prct"])}))
    |> filter(fn: (r) => r.latency_values <= 49 or r.packetLoss_values <=1)
    |> map(fn: (r) => ({r with latency_values: float(v: r["nping-avg"]), 
                            percentage_values: float(v: r["nping-pl_prct"])}))
    |> aggregateWindow(every:5m, fn: mean, createEmpty: true)    
    |> toFloat()
    |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
    |> map(fn: (r) => ({r with finalResult: r["nping-avg"]/latencyAverage}))
    |> yield(name: "jitter")

```

This is my code and the last `map()` uses `latencyAverage`

---

<div class="post-metadata">

**Author:** ![rwb](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/rwb/32/13187_2.png) [@rwb](https://community.influxdata.com/u/rwb)\
**Post date:** [April 11, 2023, 1:49pm UTC](https://community.influxdata.com/t/mathematics-with-two-variables/29434/2 "2023-04-11T13:49:20Z")

</div>

Here `latencyAverage ` and `jutter` are both streams of tables.

You want to get the `_value` in the first row in the first table.

Sometimes this will do it

```auto
|> findColumn(fn: (key) => key._field == field, column: "_value")

```

or sometimes you seem to need the more cumbersome

```auto
(tables|> tableFind(fn: (key) => true) |> getColumn(column: "_value"))[0]

```
