Splunk Search

Stats count for multiple fields in search

rockybhai
Loves-to-Learn Lots

I have a query that has multiple states represented in each log event how do i get stats based on the state values my logs look like this 

event 1 : x=true, y=true, z=false

event 2 : x=false, y=false, z=true

event 3: x=true, y= false, z=true

i want track all the scenarios where the values are true for these stages(x, y, z) like.

base_search AND (x=true or y=true or z=true) | stats count by x, y, z

statecount
x2
y1
z2

Is this possible to chart or do i have to log each state individually ? 

Labels (3)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Here's an example - the first part sets up your dataset, then shows how to use stats.

| makeresults
| eval _raw="x,y,z
true,true,false
false,false,true
true,false,true"
| multikv forceheader=1
| table x y z
| stats sum(eval(if(x="true",1,0))) as x sum(eval(if(y="true",1,0))) as y sum(eval(if(z="true",1,0))) as z
| transpose 0 column_name="state" 
| rename "row 1" as count

Hope this helps

 

0 Karma

rockybhai
Loves-to-Learn Lots

Each log statement contains only one reference to x,y,z. In your example i see you have loaded all the various states into one string. This will be represented as three messages in my case.

_raw;"setup x=true, y=false, z=false"
_raw: "setup x=true, y=true, z=false"

so when i search for setup i can get all these logs but not sure how to table these values.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The example shows 3 events, this is the part that sets up exactly the data you posted in your original post

| makeresults
| eval _raw="x,y,z
true,true,false
false,false,true
true,false,true"
| multikv forceheader=1
| table x y z

 and if you run this on its own, you get 3 events, as you posted.

So, the part you need is the stats part

 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

    Thursday, June 25, 2026  |  11AM PDT / 2PM EDT  Duration: 1 Hour (Includes live Q&A) Register to ...

Analytics Workspace deprecation

As of Splunk Cloud Platform 10.4.2604 and Splunk Enterprise 10.4, Analytics Workspace is now deprecated. ...

Splunk Developer Day Recap: Building, Publishing, and Growing on the Splunk Platform

Splunk Developer Day brought the Splunk developer community together for a practical look at what it means to ...