Splunk Search

How do I add every two rows into a seperate column?

akhera
New Member

I want to add every two rows in a column and display them in new column as new total:

Column1
1

2
5

7
8

9

NewTotalColum

3

12

17

Any leads will be helpful.

Tags (3)
0 Karma
1 Solution

renjith_nair
Legend

@akhera,

Try this,

your search|streamstats current=f window=1 last(Column1) as prev|eval rowno=1|accum rowno
|eval Total=if(rowno%2==0,Column1+prev,null())|fields - rowno,prev

You shall change the logic to display data in alternative columns if needed

---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

mstjohn_splunk
Splunk Employee
Splunk Employee

Hi @akhera,

Did the answer below solve your problem? If so, please resolve this post by approving it! If your problem is still not solved, keep us updated so that someone else can help ya. Thanks for posting!

0 Karma

akhera
New Member

@mstjohn_splunk @renjith.nair This is really helpful and it solved my issue. thanks for your help and support.

0 Karma

renjith_nair
Legend

@akhera,

Try this,

your search|streamstats current=f window=1 last(Column1) as prev|eval rowno=1|accum rowno
|eval Total=if(rowno%2==0,Column1+prev,null())|fields - rowno,prev

You shall change the logic to display data in alternative columns if needed

---
What goes around comes around. If it helps, hit it with Karma 🙂
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...