<?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 Re: Join searches and make a calculation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545618#M154589</link>
    <description>&lt;P&gt;Firstly, you should add a time element to the stats e.g. 1h buckets or whatever you choose so long as they are the same for the two queries. This will give you a field to join on i.e. _time&lt;/P&gt;</description>
    <pubDate>Fri, 26 Mar 2021 14:56:41 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2021-03-26T14:56:41Z</dc:date>
    <item>
      <title>Join searches and make a calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545605#M154583</link>
      <description>&lt;P&gt;I would like to run 2 searches and calculate the difference between 2 fields and plot the result using timechart&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tested both these searches independently and it works fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying this out&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;lt;search A&amp;gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;stats count&amp;nbsp; max(size) AS Users_Waiting | join [search &amp;lt;search B&amp;gt; | stats count as Daily_Users | streamstats sum(Daily_Users) as Cumulative_Users | timechart span=1d&amp;nbsp;Cumulative_Users-Users_Waiting&lt;/P&gt;&lt;P&gt;So basically, I want to take the count of first search which is&amp;nbsp;&lt;STRONG&gt;Users_Waiting&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Take the count of 2nd search which is&amp;nbsp;&lt;STRONG&gt;Cumulative_Users&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Draw a timechart with (&lt;STRONG&gt;Cumulative_Users -&amp;nbsp;Users_Waiting&lt;/STRONG&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Is my approach correct ?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:28:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545605#M154583</guid>
      <dc:creator>balash1979</dc:creator>
      <dc:date>2021-03-26T14:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Join searches and make a calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545610#M154584</link>
      <description>&lt;P&gt;The join will attempt to join with common fields - there are no common fields between your two queries.&lt;/P&gt;&lt;P&gt;The timechart needs a time element to work with - both queries remove this in their stats commands.&lt;/P&gt;&lt;P&gt;It is not clear where your second query finishes as there is no closing square bracket.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:41:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545610#M154584</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-26T14:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Join searches and make a calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545613#M154585</link>
      <description>&lt;P&gt;Sorry if i wasnt very clear.&lt;/P&gt;&lt;P&gt;This is search1&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;search A&amp;gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;stats count&amp;nbsp; max(size) AS Users_Waiting&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This is search 2&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;join [search &amp;lt;search B&amp;gt; | stats count as Daily_Users | streamstats sum(Daily_Users) as Cumulative_Users&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;Is there a way to do&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;Cumulative_Users-Users_Waiting (&lt;/STRONG&gt;basically difference between these 2 numbers) and then timechart the difference ?&lt;BR /&gt;Yes, I dont have any common fields between the 2 searches.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:51:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545613#M154585</guid>
      <dc:creator>balash1979</dc:creator>
      <dc:date>2021-03-26T14:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Join searches and make a calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545615#M154587</link>
      <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;join&lt;/FONT&gt; command works best when the two searches have common fields.&amp;nbsp; This example has no common fields.&amp;nbsp; What's more, &lt;FONT face="courier new,courier"&gt;join&lt;/FONT&gt; is inefficient and not needed in this case.&amp;nbsp; Also, the &lt;FONT face="courier new,courier"&gt;timechart&lt;/FONT&gt; command requires the _time field, but it is stripped out by &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt;.&amp;nbsp; Additionally, the &lt;FONT face="courier new,courier"&gt;timechart&lt;/FONT&gt; command cannot calculate the difference between two fields.&lt;/P&gt;&lt;P&gt;Try combining the searches with &lt;FONT face="courier new,courier"&gt;append&lt;/FONT&gt; then merging the results by time.&amp;nbsp; Use &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; to compute difference before invoking &lt;FONT face="courier new,courier"&gt;timechart&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;search A&amp;gt;  
| bin span=1d _time
| stats count max(size) AS Users_Waiting by _time
| append [search &amp;lt;search B&amp;gt; 
  | bin span=1d _time
  | stats count as Daily_Users by _time
  | streamstats sum(Daily_Users) as Cumulative_Users ]
| stats values(*) as * by _time
| eval Users_Not_Waiting = Cumulative_Users - Users_Waiting
| timechart span=1d Users_Not_Waiting&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:54:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545615#M154587</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-03-26T14:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Join searches and make a calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545618#M154589</link>
      <description>&lt;P&gt;Firstly, you should add a time element to the stats e.g. 1h buckets or whatever you choose so long as they are the same for the two queries. This will give you a field to join on i.e. _time&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-searches-and-make-a-calculation/m-p/545618#M154589</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-26T14:56:41Z</dc:date>
    </item>
  </channel>
</rss>

