Dashboards & Visualizations

Inactive users vs active users in the last 30 days

rajkskumar
Explorer

I want to build a Chart with two values. Inactive Users based on Customer ID and the Active Users who have used the service in the last 30 days.

 

 

index=prod  earliest=-30d AND latest=now
| eval Total = mvdedup(customerId)
| timechart span=1d dc(customerId) as "Active Users"

 

 

The above code gives me the Chart for Active Users in the last 30 days. From All time data I want to get the count of Total Users and then derive the Inactive users. (Inactive = Total users - Active users). Please help me to rewrite the query to generate the required data.

Labels (1)
0 Karma
1 Solution

FrankVl
Ultra Champion

This (ran over all-time) would get you a list of users and their status (Inactive/Active):

index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(last_seen > relative_time(now(), "-30d@d"),"Active","Inactive")

I'm not entirely sure what the end result is that you are after, but hope this helps you in the right direction.

View solution in original post

FrankVl
Ultra Champion

This (ran over all-time) would get you a list of users and their status (Inactive/Active):

index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(last_seen > relative_time(now(), "-30d@d"),"Active","Inactive")

I'm not entirely sure what the end result is that you are after, but hope this helps you in the right direction.

rajkskumar
Explorer

Hi @FrankVl,

Thank you very much for your support. This is working as expected. However, I need to add another condition to the "if" clause and I tried with the following. All the users are shown as "Inactive". Could you please point out the issue in the conditions?

index=prod 
| stats latest(_time) as last_seen by customerId, processName
| eval status = if(processName=="Execution" AND (last_seen > relative_time(now(), "-30d@d")),"Active","Inactive")


index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(match(processName,"Execution") AND (last_seen > relative_time(now(), "-30d@d")),"Active","Inactive")
0 Karma

FrankVl
Ultra Champion

In the second query, the processName field doesn't exist after the stats command, so you can't use that in the condition.

I'm not sure why the first query doesn't work. Best to investigate it by removing the eval line and look at the results of the stats command, to see if the data would actually match the condition.

To make the 'last_seen' field human readable (for easier investigation if it is within the last 30d), you can do this (at the very bottom of your query, after doing any evals/conditions that need that field):

| convert ctime(last_seen)
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...