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!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...