Splunk Search

Count of set diff from previous bucket

jberd126
Path Finder

I'm trying to produce a report that shows the difference between new and missing IDs from one day to the next day over a period of time. I've looked into this answer but I'm not sure how to apply it to my problem.

The base query

sourcetype=client | bucket _time span=1d | stats values(deviceId) by _time

gives me a set of distinct device IDs. How do I get a set of distinct device IDs from the previous day so that I can get a count of the IDs that are new and removed so that I can get a report such as this?

Date | Total | New | Removed
----------------------------
 x     5       0     1
 x+1   6       2     1
 x+2   9       3     0       
Tags (3)
0 Karma
1 Solution

dmillis
Splunk Employee
Splunk Employee

This problem is similar to the one described in how-do-i-get-results-in-search-a-that-are-not-in-search-b. Try something like this:

sourcetype=client | eval happened_recently=if(relative_time(now(),"@d")<=_time,1,0) | eval happened_before=if(relative_time(now(),"@d")>_time,1,0) | stats sum(happened_recently) AS recent, sum(happened_before) AS before by deviceId | search recent=0 OR before=0

This will show all the deviceIds which have either shown up in the past, but not today (the "recently missing"), or show up today, but not in the past (the "recently appeared"). You can obviously tweak the final search term to show only "recently missing" or "recently appeared".

View solution in original post

0 Karma

dmillis
Splunk Employee
Splunk Employee

This problem is similar to the one described in how-do-i-get-results-in-search-a-that-are-not-in-search-b. Try something like this:

sourcetype=client | eval happened_recently=if(relative_time(now(),"@d")<=_time,1,0) | eval happened_before=if(relative_time(now(),"@d")>_time,1,0) | stats sum(happened_recently) AS recent, sum(happened_before) AS before by deviceId | search recent=0 OR before=0

This will show all the deviceIds which have either shown up in the past, but not today (the "recently missing"), or show up today, but not in the past (the "recently appeared"). You can obviously tweak the final search term to show only "recently missing" or "recently appeared".

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