Splunk Search

How do I count users that have logged in at least once a month for the last 3 months?

sharonmok
Path Finder

Hi everyone,

I want to do a distinct count of users that have:

1) Logged in at least once a month AND
2) They've done this in the last 3 consecutive months.

So if they logged in only during one or two of the three months, it won't count them.

Thanks!

0 Karma
1 Solution

pradeepkumarg
Influencer

Provided you have month field extracted from your results

.. | stats dc(month) as Month_Count values(month) by USER | where Month_Count  > 3 

View solution in original post

0 Karma

niketn
Legend

@sharonmok, what are the month and user fields in your query. How do you identify Login attempt? Do you need to count only successful login or failed one as well? Can this be identified based on your data?

If you can add sample data and current query that you have tried, it will help us assist you better.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

sharonmok
Path Finder

This is what I had originally:

| dedup user_company, date_month
| stats count(user_companyname) as client_count
| eval A = (client_count /100) * 100
| table A

The last two lines were just to make it into a percentage out of the total number of users. Login attempt is just if they show up in the logs. No need to count the ones that didn't log in.

Thanks!

0 Karma

Shan
Builder

@sharonmok

You need to give a alias name.
Try the below query..

| stats dc(Month) as Month,list(Month) as Months,values(Month) as Monthss by User
| where Month>=3
| table User Month Months Monthss

Regards,
Shankarananth T

0 Karma

pradeepkumarg
Influencer

Provided you have month field extracted from your results

.. | stats dc(month) as Month_Count values(month) by USER | where Month_Count  > 3 
0 Karma

sharonmok
Path Finder

Thanks for your reply! I'm getting a 'dc' function is unsupported in 'where' command.

0 Karma

DalJeanis
Legend

That's why it is best practice to ALWAYS rename aggregate fields.

| stats dc(month) as DCmonth values(month) by USER | where DCmonth > 3

sharonmok
Path Finder

Thank you! This did exactly what I wanted it to!

0 Karma

pradeepkumarg
Influencer

I agree, should always rename aggregated fields. I posted this in rush. I'll fix the answer.

0 Karma
Get Updates on the Splunk Community!

Index This | What’s a riddle wrapped in an enigma?

September 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

BORE at .conf25

Boss Of Regular Expression (BORE) was an interactive session run again this year at .conf25 by the brilliant ...

OpenTelemetry for Legacy Apps? Yes, You Can!

This article is a follow-up to my previous article posted on the OpenTelemetry Blog, "Your Critical Legacy App ...