<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to create a search to find a percentage using my data set and display this in a timechart? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266414#M80076</link>
    <description>&lt;P&gt;First of all I am very new to splunk! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
My data can be simplified to look something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Employee = (UniqueId Id, EmployeeId ManagerId)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So we have an &lt;CODE&gt;employee record&lt;/CODE&gt; which has a &lt;CODE&gt;Id&lt;/CODE&gt; field and a &lt;CODE&gt;managerId&lt;/CODE&gt; field. The &lt;CODE&gt;managerId&lt;/CODE&gt; field contains the Id of the manager who is also an employee.&lt;BR /&gt;
So basically there can be records in &lt;CODE&gt;employee&lt;/CODE&gt; which don't have &lt;CODE&gt;managerId&lt;/CODE&gt; in them.&lt;BR /&gt;
I wanted to do a splunk search that determines the % of employees that have manager.&lt;BR /&gt;
Currently, I am doing something like this, which returns me the employees that have managers:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* host=* logRecordType=mytype managerId=* | timechart dc(Id) AS "Number of employees with manager" span=1d
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, I need to do something which will give me the % of employees that have manager over time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* host=* logRecordType=wousa|eval(managerId="*") as employeesWithManagers,count as Employees| eval(employeesWithManagers/Employees*100) as "% of total employess with managers"| --somehow timechart this over time?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search returns &lt;CODE&gt;0&lt;/CODE&gt; for &lt;CODE&gt;employeesWithManagers&lt;/CODE&gt; so I know that's incorrect.&lt;BR /&gt;
Any suggestions on how to get to the promised land will help!&lt;/P&gt;</description>
    <pubDate>Sat, 21 May 2016 22:30:07 GMT</pubDate>
    <dc:creator>jojujose</dc:creator>
    <dc:date>2016-05-21T22:30:07Z</dc:date>
    <item>
      <title>How to create a search to find a percentage using my data set and display this in a timechart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266414#M80076</link>
      <description>&lt;P&gt;First of all I am very new to splunk! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
My data can be simplified to look something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Employee = (UniqueId Id, EmployeeId ManagerId)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So we have an &lt;CODE&gt;employee record&lt;/CODE&gt; which has a &lt;CODE&gt;Id&lt;/CODE&gt; field and a &lt;CODE&gt;managerId&lt;/CODE&gt; field. The &lt;CODE&gt;managerId&lt;/CODE&gt; field contains the Id of the manager who is also an employee.&lt;BR /&gt;
So basically there can be records in &lt;CODE&gt;employee&lt;/CODE&gt; which don't have &lt;CODE&gt;managerId&lt;/CODE&gt; in them.&lt;BR /&gt;
I wanted to do a splunk search that determines the % of employees that have manager.&lt;BR /&gt;
Currently, I am doing something like this, which returns me the employees that have managers:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* host=* logRecordType=mytype managerId=* | timechart dc(Id) AS "Number of employees with manager" span=1d
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, I need to do something which will give me the % of employees that have manager over time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* host=* logRecordType=wousa|eval(managerId="*") as employeesWithManagers,count as Employees| eval(employeesWithManagers/Employees*100) as "% of total employess with managers"| --somehow timechart this over time?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search returns &lt;CODE&gt;0&lt;/CODE&gt; for &lt;CODE&gt;employeesWithManagers&lt;/CODE&gt; so I know that's incorrect.&lt;BR /&gt;
Any suggestions on how to get to the promised land will help!&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2016 22:30:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266414#M80076</guid>
      <dc:creator>jojujose</dc:creator>
      <dc:date>2016-05-21T22:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search to find a percentage using my data set and display this in a timechart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266415#M80077</link>
      <description>&lt;P&gt;Well, first off let me say welcome!&lt;/P&gt;

&lt;P&gt;Secondly, let me say EDIT FAIL.  Somehow my browser got confused and posted this while I was editing it.  Sorry.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The first technique that came to mind would be something like the following.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=X host=Y logRecordType=mytype | eval HasManager=if(isnull(managerId),0,1) | timechart eval(count/sum(HasManager)) as percentWithManager
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In that, we make sure our base search returns both events with managerId and those without.  We create a new field with a value 1 or 0 for if managerId is in that event or not - this makes it easy to do "count" style calculations.  Finally, we use a timechart of an eval'd field.  &lt;/P&gt;

&lt;P&gt;Please note that if I did things in my usual way, I did my division backwards and you'll have to fix that.  &lt;/P&gt;

&lt;P&gt;I would only use &lt;CODE&gt;span=1d&lt;/CODE&gt; in your &lt;CODE&gt;timechart&lt;/CODE&gt; only if you actually need that so that the search will auto-time span itself depending on the overall timeframe in use, but if you need it, add it.  Also, if you go to the visualization tab it will &lt;STRONG&gt;probably&lt;/STRONG&gt; pick line chart, which is appropriate, but you might need to "Format" your line chart, and in the section General, Null Values, select the right-most option "Connect".  On the other hand you may not need to - I just thought I'd mention it in case.&lt;/P&gt;

&lt;P&gt;Anyway, give that a try and reply back with any additional assistance needed!&lt;/P&gt;</description>
      <pubDate>Sun, 22 May 2016 01:54:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266415#M80077</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-05-22T01:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a search to find a percentage using my data set and display this in a timechart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266416#M80078</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* host=* logRecordType=wousa | outputcsv TEMP.csv | search managerId="*" | dedup EmployeeId | timechart span=1d count AS "employeesWithManagers"
| appendpipe [ | inputcsv TEMP.csv | search NOT managerId="*"| dedup EmployeeId | timechart span=1d count AS "employeesWithoutManagers" ]
| eval  pctEmployeesWithManagers = 100 * (employeesWithManagers/(employeesWithManagers + employeesWithoutManagers))
| fields - employeesWithManagers employeesWithoutManagers
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2016 07:42:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-search-to-find-a-percentage-using-my-data-set/m-p/266416#M80078</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-23T07:42:43Z</dc:date>
    </item>
  </channel>
</rss>

