Splunk Search

How to calculate employee retention from previous month

lbrhyne
Path Finder

Hello, We are trying to calculate employee retention by the department for the previous month. The challenge is trying to account for employee's that were not terminated from the company but transferred to a different department. What I'm attempting to do is calculate the number of employees by name within a department at the beginning and end of the previous month.

Example: There are 10 employees in Department A on January 1st and Little Johnny decide to jump ship to Department B on January 15. On Jan 31st Department A has only 9 employees, leaving a 90% retention rate for the previous month.

Thanks in advance for the help!

0 Karma
1 Solution

nareshinsvu
Builder

Try this:

| from datamodel:<your_datamodel> 
|where ((_time>relative_time(now(),"-1mon@mon") and _time<relative_time(relative_time(now(),"-1mon@mon"),"+1d")) OR (_time>relative_time(relative_time(now(),"@mon"),"-1d")   and _time<relative_time(now(),"@mon")))  
| stats count by date_mday Department 
|streamstats max(date_mday) as monthend 
|eventstats sum(count) as Total by  Department   
|eval diff=if((date_mday==monthend),Total-count,"")
|eval Percent_change = ((count-diff)/diff)*100
|fields date_mday  Department   count Percent_change

View solution in original post

nareshinsvu
Builder

Try this:

| from datamodel:<your_datamodel> 
|where ((_time>relative_time(now(),"-1mon@mon") and _time<relative_time(relative_time(now(),"-1mon@mon"),"+1d")) OR (_time>relative_time(relative_time(now(),"@mon"),"-1d")   and _time<relative_time(now(),"@mon")))  
| stats count by date_mday Department 
|streamstats max(date_mday) as monthend 
|eventstats sum(count) as Total by  Department   
|eval diff=if((date_mday==monthend),Total-count,"")
|eval Percent_change = ((count-diff)/diff)*100
|fields date_mday  Department   count Percent_change

lbrhyne
Path Finder

Thank you @nareshinsvu that worked, i think :). I just noticed that I got ahead of myself as we don't have any data for July for this index, so I won't know fully until next month. With that being said, you certainly put me on the right path!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...