# Cumulative Sum String field

**URL:** https://discuss.elastic.co/t/cumulative-sum-string-field/340216
**Category:** Kibana
**Created:** [August 7, 2023, 2:51am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216 "2023-08-07T02:51:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dro/32/131811_2.png) [@dro](https://discuss.elastic.co/u/dro)
#### Post date: [August 7, 2023, 2:51am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/1 "2023-08-07T02:51:38Z")

</div>

I've tried searching on the forum, but haven't really found something similar.

Is there a method to show a cumulative sum of a field of type `string` using Lens or TVSB? For example a field of data with string types `YES` and `NO` , I would like to show a cumulative some of the field over time.

Currently the only way I can think of doing this is creating a run time field which converts the `string` into `int` so as to enable the functionality; I.E. `YES = 1` and `NO = 2` etc.

Realistically I can also convert the data to integers pre-ingestion using a lookup table style implementation, but I was really trying to avoid doing so and wondering if there is away to just do it based directly on the field itself.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 7, 2023, 3:06am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/2 "2023-08-07T03:06:25Z")

</div>

Hi @dro

Did you try Lens with custom formula

To be clear it needs to be a `keyword` type not `text`

Lens Formula, this should work

`cumulative_sum(count(kql = 'your_field : "YES"' ))`

 ![Screenshot 2023-08-06 at 8.08.41 PM](https://us1.discourse-cdn.com/elastic/original/3X/e/4/e44c1d1871cdab80682c7d27d8f94a3e31ad01a6.png)

Formula Help is right there

 ![Screenshot 2023-08-06 at 8.08.51 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/3/93498e6b6a50fc6341bdf4daeff463ab858284b3.png)

---

<div class="post-metadata">

### Author: ![dro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dro/32/131811_2.png) [@dro](https://discuss.elastic.co/u/dro)
#### Post date: [August 7, 2023, 3:13am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/3 "2023-08-07T03:13:25Z")

</div>

I just realized the foolish mistake I was making after reading your post.

You are able to count the string field using the TSVB, but the `interval` range was set to auto so the `count` was per interval. By setting the interval range manually, you are able to show the count of the field over the entire span.

It's essentially showing a cumulative sum which is what I was looking for, but I gave myself tunnel vision by trying to do it directly with the `cumulative sum` calculation.

I will definitely be trying it your way however, because I like using the lens feature more.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 7, 2023, 3:15am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/4 "2023-08-07T03:15:01Z")

</div>

Yup Typically more than one way .. depends if you just want a number or graph, if just a total number then yes over entire range will do it!

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 7, 2023, 3:19am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/5 "2023-08-07T03:19:18Z")

</div>

You can just do a metric in Lens as well and you don't need the `cumaltive_sum` part

 ![Screenshot 2023-08-06 at 8.18.42 PM](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fe99b42ee772d5b1fc9fb741c3ac8440996c735a.jpeg)

---

<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: [September 4, 2023, 3:19am UTC](https://discuss.elastic.co/t/cumulative-sum-string-field/340216/6 "2023-09-04T03:19:19Z")

</div>

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