# How to transform values from influx to grafana

**URL:** <https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250>\
**Category:** Grafana\
**Created:** [March 9, 2021, 6:22pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250 "2021-03-09T18:22:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![surfingonthenet](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@surfingonthenet](https://community.grafana.com/u/surfingonthenet)\
**Post date:** [March 9, 2021, 6:22pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/1 "2021-03-09T18:22:49Z")

</div>

Hi,  
I use icinga2+influx+grafana and I have a specific measurement which icinga stores 0 for device UP and 3 for device DOWN.

The problem I’m facing is the graph on grafana looks like this for a UP device:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/0/070ce464426966975308a723e6a2e65260f1a1fc.png)

which sounds the opposite. So my question is:  
Is there a way to transform this value to something like (UP = 1 / DOWN = 0) for producing a more-intuitive graph?

I mean, if it’s possible to show 1 for UP and 0 for DOWN, so downtimes would be shown as valleys, that would look more intuitive

Any help would be appreciated  
Thanks

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [March 9, 2021, 8:05pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/2 "2021-03-09T20:05:26Z")

</div>

It is a task for primitive math (+,-,x,/,abs) on the InfluxQL level. Target is to get this transformation:  
3 → 0  
0 → 1

Use:

```auto
ABS(("field"/3)-1)

```

Test:  
for field value = 3: `ABS((3/3)-1) = 0`  
for field value = 0: `ABS((0/3)-1) = 1`

Note: you will need subquery if you need timegrouping, example with Grafana macros:

```auto
SELECT 
  MEAN(status) 
FROM (
  SELECT 
    ABS(("field"/3)-1) AS status 
  FROM "measurement" 
  WHERE $timeFilter
) 
GROUP BY time($__interval)

```

Some query polishing still may be needed. Of course they may be created also other more/less complicated “transformations” with the math and InfluxDB functions.

---

<div class="post-metadata">

**Author:** ![surfingonthenet](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@surfingonthenet](https://community.grafana.com/u/surfingonthenet)\
**Post date:** [March 10, 2021, 10:02pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/3 "2021-03-10T22:02:02Z")

</div>

Hi @jangaraj,  
First, let me thank you for helping me out.

Sounds good your suggestion, so let me ask a second question:  
I’m pretty new to Grafana, and I have already tried to customize the query, but I’m not getting it. When I click on the pencil icon to edit the InfluxQL query, I can edit it, but I didn’t find out how to persist it (I mean, when I click back on editor icon, the interactive query builder keeps the original query).

I’m sorry it’s a dumb question, but I didn’t find how to persist custom InfluxQL queries on Grafana. Could you point me to any doc explaining how to do it?

another point is, trying to test the custom query via influx console, trying the query below works

> SELECT state  
> FROM dummy  
> WHERE hostname = ‘myhost’ AND service = ‘myservice’  
> LIMIT 1

but when I run the query below I gt “ERR: unsupported call: abs”

> SELECT ABS(state)  
> FROM dummy  
> WHERE hostname = ‘myhost’ AND service = ‘myservice’  
> LIMIT 1

any clue to this?  
I’m using influx version 1.1.1

Thank you

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [March 10, 2021, 10:27pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/4 "2021-03-10T22:27:44Z")

</div>

You can’t toggle between editor modes. Use always RAW mode, where you have to write query manually. UI mode is only for basic simple queries.

I guess your InfluxDB 1.1.1 is very old (current version is 1.8.x) and it doesn’t support ABS function.

---

<div class="post-metadata">

**Author:** ![surfingonthenet](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@surfingonthenet](https://community.grafana.com/u/surfingonthenet)\
**Post date:** [March 10, 2021, 10:46pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/5 "2021-03-10T22:46:24Z")

</div>

That helps me a lot  
Thank you very much @jangaraj

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [March 9, 2022, 6:23pm UTC](https://community.grafana.com/t/how-to-transform-values-from-influx-to-grafana/44250/6 "2022-03-09T18:23:08Z")

</div>

Closed on March 9, 2022, 6:23pm UTC

This topic was automatically closed after 365 days. New replies are no longer allowed.
