Splunk Search

Need Help with sum over two columns without subsearch

PPape
Contributor

Hi Guys,

I need some help with a stats command.

Given is Data like this csv

Round,Player1,Player2,ScorePlayer1,ScorePlayer2
1,Harry,Tom,5,1
2,Eva,Mike,1,0
3,Harry,Eva,3,4
4,Mike,Tom,4,6
5,Tom,Harry,3,2
6,Mike,Eva,7,5
7,Eva,Tom,2,5

All I want to have is a stats command that gives me a table with the total amount of points for every player.
I managed to do it with a subsearch but this feels kind of weird... there has to be a better solution.

0 Karma
1 Solution

sundareshr
Legend

Try this

base search here | eval player=player1.";".player2 | eval score=ScorePlayer1.";".ScorePlayer2 | makemv player delim=";" | makemv score  delim=";" | eval z=mvzip(player, score) | mvexpand z | rex field=z "(?<player>[^;]+);(?<score>.*)" | stats sum(score) as score by player

View solution in original post

sundareshr
Legend

Try this

base search here | eval player=player1.";".player2 | eval score=ScorePlayer1.";".ScorePlayer2 | makemv player delim=";" | makemv score  delim=";" | eval z=mvzip(player, score) | mvexpand z | rex field=z "(?<player>[^;]+);(?<score>.*)" | stats sum(score) as score by player

PPape
Contributor

There is a little mistake. The mvzip command uses an comma as seperator so the semikolon in the rex command must be replaced with an comma. Than it works perfectly! Thank you again

0 Karma

PPape
Contributor

Thank you very much. This worked and is faster than my subsearch.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...