# How to sum the values in the column (bytes) and convert it GB?

**URL:** https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563
**Category:** Kibana
**Tags:** lens
**Created:** [February 2, 2023, 4:16pm UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563 "2023-02-02T16:16:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![maskrider1111](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maskrider1111/32/116613_2.png) [@maskrider1111](https://discuss.elastic.co/u/maskrider1111)
#### Post date: [February 2, 2023, 4:16pm UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563/1 "2023-02-02T16:16:01Z")

</div>

Hey Folks,

I'm struggling to sum the value in record (bytes) and visualize it in table. Any idea how would i achieve the SUM and converted to GB?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/a/5a3a9f4518fef22eabbed46ae0bb20b7f0121767.png)

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6c894630ccccf3a5f9b83fa13879a7220444db97.png)

![image](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4a6860c04fc25915244d8042e8a5e50285007351.png)

---

<div class="post-metadata">

### Author: ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)
#### Post date: [February 5, 2023, 5:22pm UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563/2 "2023-02-05T17:22:54Z")

</div>

You can't `sum` keyword fields, they need to be a [numeric mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html). You can either re-map the field as a number, or you can use a runtime field to make a temporary copy of the keyword field to use as a number field. [Sum aggregation | Elasticsearch Guide [8.6] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html#_script_14) provides somewhat of an example of using a runtime field. Note: this method will be slower than using a natively mapped number field.

---

<div class="post-metadata">

### Author: ![Arshukla](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Arshukla](https://discuss.elastic.co/u/Arshukla)
#### Post date: [February 6, 2023, 9:54am UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563/3 "2023-02-06T09:54:35Z")

</div>

Hello @maskrider1111

Use TSVB option instead of Lens, In TSVB u can choose Options and drop down menu under Data Formatter will be having Bytes. and in parallel column, you can divide or multiply to create GBs/MBs/ or TBs as per requirement

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/0/e09815145aff295ef2bd9782dae98c0df3c46a37.png)

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [February 6, 2023, 11:19am UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563/4 "2023-02-06T11:19:12Z")

</div>

@maskrider1111 what's the field type for the `sentbyte` and `rcvdbyte`? It looks like they are mapped as strings/keywords.

Perhaps a solution I could suggest is to create two `runtime field` for each of the two, when values are parsed as `double` (or any numeric type) and then apply a `Sum` operation in Lens.  
The content of the runtime field can be the following:

```auto
if(!doc['sentbytes'].isEmpty()){
    emit(Integer.parseInt((doc['sentbytes'].value)))
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 6, 2023, 11:19am UTC](https://discuss.elastic.co/t/how-to-sum-the-values-in-the-column-bytes-and-convert-it-gb/324563/5 "2023-03-06T11:19:23Z")

</div>

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