Splunk Search

Merging 2 stats from one search query

klaudiac
Path Finder

Hi guys, 

This little (?) thing's has been wrecking my head all weekend. I'm trying to merge 2 stats commands, or somehow make my search look neater. 

I want to see the number of emails sent to a specific person, but some of the events are showing up as 1, despite having few recipients.   

klaudiac_0-1603787876801.pngklaudiac_0-1603787876801.png

 

The only way i can get this result is where I do 2 separate stats commands one after the other: 

| stats last(eventTime) as Detected_Time , values(quarantineFolder) as Type , values(senderIP) as Sender_IP , values("threatsInfoMap{}.threatType") as threat_type, values("threatsInfoMap{}.threat") as threat, values("threatsInfoMap{}.threatUrl") as threatUrl, values(malwareScore) as malwareScore by Email_Sender Email_Recipient
| eventstats count as Recipient_occurrence by Email_Recipient
| stats last(Detected_Time) as Detected_Time , values(Email_Recipient) as Email_Recipient list(Recipient_occurrence) as Recipient_occurrence values(Type) as Type , values(Sender_IP) as Sender_IP , values(threat_type) as threat_type, values(threat) as threat, values(threatUrl) as threatUrl, values(malwareScore) as malwareScore by Email_Sender
| where isnotnull(Email_Sender)

 

Is there any other way to make it look better and more tidy?

Any help and tips will be greatly appreciated! 

Labels (3)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The two stats commands group by different fields so they cannot be merged.

---
If this reply helps you, Karma would be appreciated.
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!

Data Management Digest – August 2026

MichelleCorpora_1-1788182384472.png Welcome to the August 2026 edition of Data Management Digest! August was a ...

Your Feedback. Our Roadmap. Visit the PX Feedback Booth at .conf26

You use Splunk every day, come and help shape what's next.  Save Your Seat: Product-Focused Sessions at ...

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...