Splunk Search

Searching back in time to determine newness (or not) of a value in a given field

JohnR
Engager

Given a field containing a "userId", I want a count per day of unique userIds by "new" vs "returning". E.g. Ends up with this output...

| timechart span=1d dc(userId) by newOrReturning

or I suppose...

| bin _time span=1d
| stats dc(userId) by _time, newOrReturning

A userId is "new" on a given day if there is no record of it from any previous day, going as far back as a known fixed date.

The bit I'm having trouble with is how to set newOrReturning, since (I assume) I need to somehow search back in time for a matching userId from previous days.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this (set time period to be all time or since whatever date you want to consider)

| bin _time span=1d
| eventstats earliest(_time) as firsttime by userid
| eval newOrReturning=if(_time=firsttime,"New","Returning")
| stats dc(userId) by _time, newOrReturning

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this (set time period to be all time or since whatever date you want to consider)

| bin _time span=1d
| eventstats earliest(_time) as firsttime by userid
| eval newOrReturning=if(_time=firsttime,"New","Returning")
| stats dc(userId) by _time, newOrReturning
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...