Splunk Search

How can I count values by a subgroup?

yk010123
Path Finder

I have the following data : 

 

ServiceMessage
Service1Hello world
Service2Another message
Service1Hello world
Service1Some other message

 

How can I write a query such that the final output looks like : 

Service : Unique message : count

For example : 

Service1 : Hello World :   2

Service1:Some other message : 1

Service2: Some other message

Labels (1)
0 Karma
1 Solution

VatsalJagani
SplunkTrust
SplunkTrust

Try:

<your current search>
| stats count by Service, Message

 

I hope this helps!!!

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@yk010123 

Add custom field in @VatsalJagani search to get values in desired format.

YOUR_SEARCH
| stats count by Service Message
| eval custom_field=Service.":".Message.":".count

 My Sample Search :

 

| makeresults | eval _raw="Service	Message
Service1	Hello world
Service2	Another message
Service1	Hello world
Service1	Some other message" | multikv forceheader=1
| table Service	Message
| rename comment as "Upto now is for sample data only"
| stats count by Service Message
| eval custom_field=Service.":".Message.":".count

 

Thanks
KV


If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Try:

<your current search>
| stats count by Service, Message

 

I hope this helps!!!

Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...