Splunk Search

How to calculate the total in a time range based on it own time stamp?

suntianze
New Member

alt text

I want a table that looks like this. Where the first column UserID is the identity. The second column is the earliest timestamp when the ID appears. The sum of the viewing time of the third column relative to the 3 days after the ID appeared. I don't know how to set the time range, because the time is three days after the earliest time stamp. And it is different for each ID.

Tags (1)
0 Karma

to4kawa
Ultra Champion
index=yours event_extra_userInfo_userId=* 
| bin _time span=1d
| stats earliest(timesatmp) as first_appear count as day_count by _time event_extra_userInfo_userId
| eventstats min(first_appear) as firstTime by event_extra_userInfo_userId
| eventstats sum(eval(if(_time <= relative_time(firstTime,"+3d@d") , day_count, NULL))) as total by event_extra_userInfo_userId

Where the first column UserID is the identity
There is not UserID in your sample pic.

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!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...