# Mathematic to different columns

Hello!

I have this flux command:

``````from(bucket: "data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "PV")
|> filter(fn: (r) => r["Wechselrichter"] == "1")
|> filter(fn: (r) => r["String"] == "1" or r["String"] == "2")
|> filter(fn: (r) => r["_field"] == "power")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "mean")
``````

So I get 2 tables or 2 columns?

I want to set a mathematic operation on both values, but not the same:
String 1: _value * 100 /3700
String 2: _value * 100 / 5940

With a map I always calc both elements … how can I set different mathematic operations?

Thank you!

Hello @hanhoe,
Make sure you’re using int or float when you perform the math.
You can do the following:
solution 1:

``````data = from(bucket: "data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "PV")
|> filter(fn: (r) => r["Wechselrichter"] == "1")
|> filter(fn: (r) => r["_field"] == "power")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

data1= data
|> filter(fn: (r) => r["String"] == "1")
|> map(fn: (r) => ({r with _value: r._value * 100/3700}))
|> yield(name: "data1")

data2= data
|> filter(fn: (r) => r["String"] == "1")
|> map(fn: (r) => ({r with _value: r._value * 100/5940}))
|> yield(name: "data1")
``````

solution 2

``````from(bucket: "data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "PV")
|> filter(fn: (r) => r["Wechselrichter"] == "1")
|> filter(fn: (r) => r["String"] == "1" or r["String"] == "2")
|> filter(fn: (r) => r["_field"] == "power")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> map(
fn: (r) => ({r with
_value: if r.String == "1" then
r._value * 100/3700
else
r._value * 100/5940,
}),
)
``````

The first solution is more performant most likely.
Thank you

Hi @Anaisdg one question: how can I use the variable data1 in data2?
For example, lets asumme that data1 returns one value as in `|> mean()`

in data2, can I do the following?:

``````data2= data
|> filter(fn: (r) => r["String"] == "1")
|> map(fn: (r) => ({r with _value: r._value * data1}))
|> yield(name: "data2")
``````

Thanks