Splunk Search

How to use an addcoltotals result for eval?

splunkreal
Motivator

Hello dear Splunk experts 🙂

I have this in my search:

addcoltotals labelfield=fieldtosum label=TOTAL

However I would like to reuse the result of it like fieldtosum/TOTAL, how to do?

Example attached.

alt text

Thanks.

* If this helps, please upvote or accept solution 🙂 *
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try like this

your current search | eventstats sum(fieldtosum) as TOTAL | addcoltotals labelfield=fieldtosum label=TOTAL | eval  fieldtosum=fieldtosum/TOTAL

View solution in original post

splunkreal
Motivator

Here is the search :

| multisearch [ search index="xxx" sourcetype="XXX_Search" | where NB_Result = 0 | rename NB_Result as SZERO ] [ search index="xxx" sourcetype="XXX_Search" | where NB_Result > 1 ] | stats count(AZERO) as totalsearch, count (SZERO) as totalfailed by Result | eval wresult=round(totalfailed/(totalfailed+totalsearch)*100,0) | eval ctotal=totalfailed+totalsearch | eval Searches=case(Result="null","Something", Result="YES","Yes",Result="NEAR","Near") | eventstats sum(Searches) as totalr | table Searches,totalsearch,totalfailed, ctotal, wresult, totalr

Field totalr is empty however totalr is not empty if I use eventstats sum(wresult) as totalr

So is it a problem with case?

Thanks.

* If this helps, please upvote or accept solution 🙂 *
0 Karma

woodcock
Esteemed Legend

This is very helpful but I need to see the actual output, too, (which is what I was asking to see before). What I mean is that you obviously don't have field names A, B, and C. Your search shows that you should have 5 fields. Show your output as it really is (good and bad).

0 Karma

woodcock
Esteemed Legend

Your picture does not match your search. Type it in and get the field names correct.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

your current search | eventstats sum(fieldtosum) as TOTAL | addcoltotals labelfield=fieldtosum label=TOTAL | eval  fieldtosum=fieldtosum/TOTAL

splunkreal
Motivator

It works!

I was using the wrong fieldtosum : it's ok with eventstats sum(totalsearch) as totalr

* If this helps, please upvote or accept solution 🙂 *
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...