# Adding incremental column based on values of another column

**URL:** https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443
**Category:** Logstash
**Created:** [November 4, 2023, 4:15pm UTC](https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443 "2023-11-04T16:15:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Felicien\_Ihirwe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felicien_ihirwe/32/127227_2.png) [@Felicien\_Ihirwe](https://discuss.elastic.co/u/Felicien_Ihirwe)
#### Post date: [November 4, 2023, 4:15pm UTC](https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443/1 "2023-11-04T16:15:20Z")

</div>

I want to create a logstash filter to come from table 1 to table 2:

col1  
in  
in  
out  
in  
out  
..  
.

I want to add a new column that will contain incremental values and the data will look like  
col1 | col 2  
in | 1  
in | 1  
out | 1  
in | 2  
out | 2  
.. | 3  
.

any help?

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [November 4, 2023, 10:38pm UTC](https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443/2 "2023-11-04T22:38:20Z")

</div>

logstash is not a good fit for this task. You would have to write a ruby filter to keep track of the values to be added in the second column. You would also need a single worker thread (pipeline.workers 1) and make sure that pipeline.ordered evaluates to true.

---

<div class="post-metadata">

### Author: ![Felicien\_Ihirwe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felicien_ihirwe/32/127227_2.png) [@Felicien\_Ihirwe](https://discuss.elastic.co/u/Felicien_Ihirwe)
#### Post date: [November 16, 2023, 3:13pm UTC](https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443/3 "2023-11-16T15:13:58Z")

</div>

Thank you for your answer.. it works and I was able to solve it. I used the in and out values to differentiate the start and the end of the aggregation tasks.. but now I have another issue:

what if the left column is not a preknown value? for instance a continuous number like this:

col1  
2.3  
2.3  
2.3  
5.7  
5.7  
6.1  
6.1  
....  
..  
.

I want to achieve this:  
col1 | col2  
2.3 | 1  
2.3 |1  
2.3 |1  
5.7 |2  
5.7 |2  
6.1 |3  
6.1 |3  
....  
..  
.

---

<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: [December 14, 2023, 3:14pm UTC](https://discuss.elastic.co/t/adding-incremental-column-based-on-values-of-another-column/346443/4 "2023-12-14T15:14:38Z")

</div>

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