Splunk Search

How do I subtract values from different events and fields based on a common field?

thomaszheng
New Member

Please help, I'm stuck on this problem for a while. Basically, lets say I have different events with fields like this. Basically I need a way to subtract a count from two different fields from two different events. Those two events only have 1 common field to somehow tie them together.

Event1)
session_id: 123 error: 1

Event2)
session_id: 123 request: 1 email: user1@gmail.com
session_id: 123 request: 1 email: user1@gmail.com
session_id: 321 request: 1 email: user2@gmail.com

Result)
email request successful_request
user1@gmail.com 2 1
user2@gmail.com 1 1

Tags (2)
0 Karma

arjunpkishore5
Motivator

Try this. Please mark as answer if this works for you.

|union 
   [search 1]
   [search 2]
| stats values(email) as email, sum(request) as request, sum(error) as error by session_id
| eval successful_request=request - error
| fields - error, session_id
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...