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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...