# How to reverse a value?

**URL:** <https://discourse.nodered.org/t/how-to-reverse-a-value/83089>\
**Category:** General\
**Created:** [22 November 2023 11:37 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089 "2023-11-22T11:37:56Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 12:16 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/21 "2023-11-25T12:16:00Z")

</div>

Having googled a bit this link may be helpful. [Calculate percentages with Flux | InfluxDB Cloud (TSM) Documentation](https://docs.influxdata.com/influxdb/cloud/query-data/flux/calculate-percentages/#:~:text=To%20calculate%20a%20percentage%20in,row%20and%20calculate%20a%20percentage.&text=Use%20from()%20%2C%20range(),align%20operand%20values%20into%20rows).

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 13:13 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/22 "2023-11-25T13:13:37Z")

</div>

Thank you, I already found that site a couple days ago but couldn’t figure out how to do it like described there.  
I’ll have another look and see if I can understand now.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 14:01 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/23 "2023-11-25T14:01:34Z")

</div>

With flux being deprecated, do you know what the recommended method of querying in Grafana will be?

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 14:12 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/24 "2023-11-25T14:12:52Z")

</div>

I honestly don’t know. In influx I go in my bucket, check my datapoint and click on script builder.  
Then I have this code:

```auto
from(bucket: "boden-wz")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "monstera")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

```

That’ll just copy-paste in grafana.  
Tbh I’m totally new to all this. I just followed some tutorials and failed around.  
My target was to play through a tool chain to see if I can do it.  
So I hope my answer helps a bit, I wish I could tell more.

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 15:01 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/25 "2023-11-25T15:01:41Z")

</div>

Ok so in influx it makes sense I guess. I just don’t know how to name the value, everything I tried so far, failed.

```auto

  |> map(fn: (r) => ({ r with _value: 100.0 * (2850.0 - "_field") / (2850.0 - 1250.0) }))

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 15:24 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/26 "2023-11-25T15:24:27Z")

</div>

Where did you put that? Before the aggregateWindow or after it?  
Doesn't the yield at the end name it?

You would save influx a little time by using

`{ r with _value: 0.0625 * (2850.0 - "_field")`}

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 15:35 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/27 "2023-11-25T15:35:03Z")

</div>

> [@Colin](#):
>
> Where did you put that? Before the aggregateWindow

Yes, I put it right before that line.

> [@Colin](#):
>
> Doesn't the yield at the end name it?

It’s also just a string,:

```auto
  |> yield(name: "mean")

```

> [@Colin](#):
>
> You would save influx a little time by using

Just like that? Not the map before it?

```auto
  |> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - "_field")})

```

It doesn’t matter btw if it’s field or mean, the error stays the same, it’s expecting an float but I have no idea what language that is, so I don’t know how to google how I convert that string

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 15:59 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/28 "2023-11-25T15:59:20Z")

</div>

> [@eli5](#):
>
> > [@Colin](#):
> >
> > Doesn't the yield at the end name it?
> 
> It’s also just a string,:

What else can the name be? I apparently don't understand what you mean by not knowing how to name it.

> [@eli5](#):
>
> Just like that? Not the map before it?

With the map, I was just suggesting a simpler formula to use (100/(2850-1250) is 0.0625)

> [@eli5](#):
>
> It doesn’t matter btw if it’s field or mean, the error stays the same, it’s expecting an float

You did not say there is an error, I thought it was working but with the wrong name against the line. What is the error?

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 16:33 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/29 "2023-11-25T16:33:15Z")

</div>

> [@Colin](#):
>
> I apparently don't understand what you mean by not knowing how to name it.

Well, somehow I have to address the value or the variable it’s in. That’s what I meant with that.

> [@Colin](#):
>
> I was just suggesting a simpler formula to use

Ah, sorry I didn’t get that before.

> [@Colin](#):
>
> What is the error?

```auto

error @5:58-5:66: expected float but found string

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 17:17 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/30 "2023-11-25T17:17:32Z")

</div>

OK, I understand. Try

```auto
 |> map(fn: (r) => ({ r with _value: 0.0625 * (2850.0 - r._value) })

```

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 17:36 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/31 "2023-11-25T17:36:49Z")

</div>

That gives me a different error:

```auto
compilation failed: error @7:6-7:70: expected RPAREN, got EOF

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 19:38 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/32 "2023-11-25T19:38:39Z")

</div>

Looks like you have lost a right parenthesis.  
If you can't see it post the whole query here

Edit: there should be another one on the end.

---

<div class="post-metadata">

**Author:** ![eli5](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eli5/32/84913_2.png) [@eli5](https://discourse.nodered.org/u/eli5)\
**Post date:** [25 November 2023 19:52 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/33 "2023-11-25T19:52:49Z")

</div>

Yes, now it looks pretty good!  
Thank you very much! Hopefully will some noobs (as me) find this thread and get helpful informations. The beginning is pretty harsh!

 ![Bildschirmfoto 2023-11-25 um 20.51.06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0be7381a8c83b86f58f7ff9d0f3c4469ddce156.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 November 2023 20:02 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/34 "2023-11-25T20:02:41Z")

</div>

Excellent

---

<div class="post-metadata">

**Author:** ![DocMors](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@DocMors](https://discourse.nodered.org/u/DocMors)\
**Post date:** [27 November 2023 13:22 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/35 "2023-11-27T13:22:16Z")

</div>

Der einfachste Weg ist vermutlich  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/081f5409f7882c4f07f74a8c5cbce09e038012c8.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 December 2023 13:22 UTC](https://discourse.nodered.org/t/how-to-reverse-a-value/83089/36 "2023-12-11T13:22:44Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/how-to-reverse-a-value/83089.md?page=1)
