# Query: Calculate % using multiple fields

**URL:** <https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032>\
**Category:** InfluxDB 2\
**Tags:** query, flux\
**Created:** [August 5, 2022, 10:16pm UTC](https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032 "2022-08-05T22:16:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-neagoe](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/a-neagoe/32/10695_2.png) [@a-neagoe](https://community.influxdata.com/u/a-neagoe)\
**Post date:** [August 5, 2022, 10:16pm UTC](https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032/1 "2022-08-05T22:16:17Z")

</div>

Hello,

I have this query working in overwriting my original hrStorageUsed and hrStorageSize fields with disk allocation units by using map function:

from(bucket: “db-snmp-synology”)  
|\> range(start: v.timeRangeStart, stop: v.timeRangeStop)  
|\> filter(fn: (r) =\> r[“\_measurement”] == “hrStorageTable”)  
|\> filter(fn: (r) =\> r[“\_field”] == “hrStorageUsed” or r[“\_field”] == “hrStorageSize”)  
|\> filter(fn: (r) =\> r[“hrStorageIndex”] == “53”)  
|\> group()  
|\> pivot(rowKey: [“\_time”], columnKey: [“\_field”], valueColumn: “\_value”)  
|\> map(fn: (r) =\> ({r with hrStorageSize: r.hrStorageSize \* 4096}))  
|\> map(fn: (r) =\> ({r with hrStorageUsed: r.hrStorageUsed \* 4096}))  
|\> drop(columns: [“\_start”, “\_stop”])

How could I calculate the used percentage from the above query?

if I use:

|\> map(fn: (r) =\> ({r with percent\_used: r.hrStorageUsed / r.hrStorageSize \* 100}))

would return 0 and would probably be some kind of integer overflow.

if I go with float, it won’t work either:

|\> map(fn: (r) =\> ({r with percent\_used: float(v: r.hrStorageUsed / r.hrStorageSize \* 100)}))

Screenshot:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a5186146586e071c14107513c6288d491d1db99e.png)

How could I make this work?

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 8, 2022, 5:47pm UTC](https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032/2 "2022-08-08T17:47:12Z")

</div>

Hello @a-neagoe,  
Can you please navigate to the raw data view? Lets verify that you’re getting actual percentages and that the reason you’re seeing 0 values is because of rounding.

 ![Screen Shot 2022-08-08 at 12.46.14 PM](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/7/7627d4e7fe66d27d1769d0f3ee46fd5387fb71d3.jpeg)  
Next, go to **customize** and change the number of decimal places pleaseee and see if that helps? Thank you.

---

<div class="post-metadata">

**Author:** ![a-neagoe](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/a-neagoe/32/10695_2.png) [@a-neagoe](https://community.influxdata.com/u/a-neagoe)\
**Post date:** [August 8, 2022, 8:17pm UTC](https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032/3 "2022-08-08T20:17:51Z")

</div>

thank you very much for the help.

the values are actually all longs after seeing the raw data. if I manually adjust one of the values to less decimals, I would get some return values:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/b/bb2e804dd5e0ce26658703449f094cab2de40430.png)

If I just adjust the outputs just to be readable in grafana, I could work the percentage out with two transformation but is less ideal than directly returning all values directly from flux.

|\> map(fn: (r) =\> ({r with \_value: r.hrStorageUsed/ r.hrStorageSize \* 100}))  
this would still return 0

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 8, 2022, 10:03pm UTC](https://community.influxdata.com/t/query-calculate-using-multiple-fields/26032/4 "2022-08-08T22:03:56Z")

</div>

@a-neagoe,  
I’m confused it seems like its working?
