Splunk Search

How to count min max time by user?

t874560
New Member

Hello,

I am trying to pull min and max time for each user:

index="iptv_rdkb" [|inputlookup usersfile.csv]
| fields _time Source device.make model userId
| stats count by Source make model userId _time
| eventstats max(_time) AS max min(_time) AS min
| eval max=strftime(max, "%Y/%m/%d %T.%3Q")
| eval min=strftime(min, "%Y/%m/%d %T.%3Q")
| stats earliest(min) as min earliest(max) as max first(make) as make first(model) as model first(userId) as user by userId

Results:

Source min max make model userid
b661834 2020-04-10 2020/04/10 TECHN xyz 1
b654623 2020-04-10 2020/04/10 TECHN xyz 2
b637895 2020-04-10 2020/04/10 TECHN xyz 3

This search gives me the same time for each record. For example, if minimum time is 2020-04-10 in any of the records, it will give this date/time in every record instead of giving min-max of that specific user.

I need min and max for each specific user.

Please help.

0 Karma

Vijeta
Influencer

@t874560 Use this search

 index="iptv_rdkb" [|inputlookup usersfile.csv]
 | fields _time Source device.make model userId
 | stats count by Source make model userId _time
 | eventstats max(_time) AS max min(_time) AS min by userId
 | eval max=strftime(max, "%Y/%m/%d %T.%3Q")
 | eval min=strftime(min, "%Y/%m/%d %T.%3Q")
 | stats earliest(min) as min earliest(max) as max first(make) as make first(model) as model first(userId) as user by userId
0 Karma

to4kawa
Ultra Champion

eventstats can use by clause.

0 Karma
Get Updates on the Splunk Community!

Federated Search for Amazon S3 | Key Use Cases to Streamline Compliance Workflows

Modern business operations are supported by data compliance. As regulations evolve, organizations must ...

New Dates, New City: Save the Date for .conf25!

Wake up, babe! New .conf25 dates AND location just dropped!! That's right, this year, .conf25 is taking place ...

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud  In today’s fast-paced digital ...