Splunk Search

How to calculate and display in a table the average of each user's field values for n number of days?

pavanae
Builder

I have a search which gives the result as follows for one day

Query :- base search | stats dc(dCIF) as dUniqueCIFs by user |eventstats avg(dUniqueCIFs) as avgdUniqueCIFs |stats max(dUniqueCIFs) as max_dUniqueCIFs max(avgdUniqueCIFs) as avgdUniqueCIFs by user

Users     dc(users_activity_count)     average(All_users_activity_count)
A                             2                                2              
B                             3                                2               
C                             1                                2                

Similarly how can I calculate the average of each users_activity count for n number of days like below

Users     dc(users_activity_count)     average(All_users_activity_count)   average(each_users_activity_count_forlast7days)
A                             2                               2                      A's average for last 7 days     
B                             3                               2                      B's .......
C                             1                               2                      C's.........

Where average(each_users_activity_count_forlast7days) should display the average of each user for last 7 days, which is user A's Average,B's,C's....

0 Karma
1 Solution

sundareshr
Legend

Try something like this

base search earliest=-7d@d
| bin span=1d _time
| stats dc(dCIF) as dUniqueCIFs by _time user 
| eval when=if(_time<relative_time(now(), "@d"), "7days", "Today")
| eventstats avg(dUniqueCIFs) as avgdUniqueCIFs by when
| table user dUniqueCIFs 7days Today 
| dedup user

View solution in original post

0 Karma

sundareshr
Legend

Try something like this

base search earliest=-7d@d
| bin span=1d _time
| stats dc(dCIF) as dUniqueCIFs by _time user 
| eval when=if(_time<relative_time(now(), "@d"), "7days", "Today")
| eventstats avg(dUniqueCIFs) as avgdUniqueCIFs by when
| table user dUniqueCIFs 7days Today 
| dedup user
0 Karma

pavanae
Builder

didn't worked. My query is as follows

base search | stats dc(dCIF) as dUniqueCIFs by user |eventstats avg(dUniqueCIFs) as avgdUniqueCIFs |stats max(dUniqueCIFs) as max_dUniqueCIFs max(avgdUniqueCIFs) as avgdUniqueCIFs by user

Based on your suggestion. I'd modified and the result successfull displayed the dUniqueCIFs which I mentioned as dc(users_activity_count) in my question but didn't seen the average and 7days average. @sundareshr

0 Karma

sundareshr
Legend

Try the updated query

0 Karma

pavanae
Builder

still the same no results for 7days and today. @sundareshr

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...