Hi,

I’m new to flux. I already figured out some (basic) things but ‘math’ with the value’s is still complex.

I am having trouble getting the ‘map’ function to work.

So I was hoping someone could help me out.

my situation:

I have now this function:

```
from(bucket: "HomeData")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "PowerMeter")
|> filter(fn: (r) => r["_field"] == "kWhFromGrid")
|> aggregateWindow(every: 1d, fn: last, createEmpty : false, timeSrc:"_start")
|> difference()
|> aggregateWindow(every: 1mo , fn: sum, createEmpty : false, timeSrc:"_start")
```

this gives me this data representation:

this is my engergy (in kWh) used in the month.

but now i want to show the cost of this so i need to multiply this number by the cost of energy.

I am not sure if i can do this after the ‘aggregateWindow’ fuction? or do i need to use a ‘map’ function after the ‘filter’ function? and if so, how do i need to to this map fuction? i tried several things allready but without luck.

(I am doing this in Grafana)

Regards,

Thomas

Hello @Thomas_Decock,

So you just need to multiply your “kWhFromGrid” column by a your cost, we’ll use variable `cost`

?

First, check if your value is a float or int.

You might need to change your `cost`

to match the type of your kWhFromGrid:

https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/float/

https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/int/

Then add this:

```
map(fn: (r) => ({cost: r.kWhFromGrid * float(v:cost) }))
```

You can add that to the end of your query, or after you’ve gotten your data in the right shape to where your kWhFromGrid column has the values you want.

If this doesn’t work for you please let me know. Also consider using a query to transform your data to right before you’re getting stuck (but reduce the time range to just return a few records) and share the annotated CSV with me so I can work with your data on my end.

@Anaisdg

costs are typically also time series and different sources have different costs. So i wonder how to do it in a time series way, even when the updates happens only every 2 years …or so. So what I’m looking for is a way to get the valid cost in a given period.

Example I want to have the energy cost for the range -1d, now() and the cost series had the last entry at 01.07.2021 and is valid until now()