Splunk Search

how to count values from a filed and show count as column

siddhardhans
Explorer

i am running below query to get total count by date_mday.


search query | eval ver=substr(av,1,4) | stats count(ver) by date_mday

and getting results for total count by month day. 

date_mdaycount
123
225
335
421

 

However, i want the results as ver count and total count - something like

date_mdayver1234ver2345ver3456ver4567total Count
110201123
2952925
311741335
48021121

 

Since eval (eval ver=substr(av,1,4)) is dynamically populating the values to ver - I can't use | stats count(eval()) function. Please help me out.

Labels (2)
0 Karma
1 Solution

DalJeanis
Legend

Try this

 

search query 
| eval ver=substr(av,1,4)
| chart count by date_mday ver
| addtotals fieldname="Total Count"
| addcoltotals labelfield=date_mday label="All Days"

 

 

View solution in original post

0 Karma

DalJeanis
Legend

Try this

 

search query 
| eval ver=substr(av,1,4)
| chart count by date_mday ver
| addtotals fieldname="Total Count"
| addcoltotals labelfield=date_mday label="All Days"

 

 

0 Karma

siddhardhans
Explorer

@DalJeanis  this is great - any suggestion to get total count on these dynamic columns?

0 Karma

DalJeanis
Legend

 

| addtotals fieldname="Total Count"
| addcoltotals labelfield=date_mday label="All Days"

 

The addtotals command will add up the totals horizontally, the addcoltotals will add them vertically.

I've updated the code above to include these.

 

0 Karma

siddhardhans
Explorer

@DalJeanis - thank you so much - i am able to see the table the way i needed. 

Tags (1)
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

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 ...