<?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: use stats within join in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434816#M124038</link>
    <description>&lt;P&gt;Hi @anjo5 &lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* sourcetype=B 
| `Renaming` 
| eval Finished = MessageTimeStamp 
| fields Finished OrderId 
| append 
    [ search index=* sourcetype=A 
    | `Renaming` 
    | eval Started = MessageTimeStamp 
    | fields Started OrderId] 
| append 
    [ search index=* sourcetype=C 
    | stats count as count by OrderId 
    | fields OrderId count] 
| stats values(Started) as Started values(Finished) as Finished by OrderId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
    <pubDate>Mon, 28 Jan 2019 19:22:44 GMT</pubDate>
    <dc:creator>chrisyounger</dc:creator>
    <dc:date>2019-01-28T19:22:44Z</dc:date>
    <item>
      <title>use stats within join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434814#M124036</link>
      <description>&lt;P&gt;I have been struggling with creating a proper query for the last hour, but I fail to understand how to achieve what I need, so hopefully you can help me out.&lt;/P&gt;

&lt;P&gt;I want to make a combination from 3 different source types, all having '*.OrderId' as field on which they should be joined.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;From sourcetype A, I want to obtain MessageTimeStamp as start time.&lt;/LI&gt;
&lt;LI&gt;From sourcetype B, I want to obtain MessageTimeStamp as end time.&lt;/LI&gt;
&lt;LI&gt;From sourcetype C, I want to count the number of messages which occurred having a given OrderId.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I want to report this in a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;OrderId | start time | end time | count(sourcetype C)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To join start and endtime, I already have the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* sourcetype=A | `Renaming`  | join type=outer OrderId 
[ search index=* sourcetype=B
| `Renaming` 
| eval "B.MessageTimeStamp"=MessageTimeStamp] | join type=outer OrderId 
[ search index=* sourcetype=A
| `Renaming` 
| eval "A.MessageTimeStamp"=MessageTimeStamp] | rename A.MessageTimeStamp as Started B.MessageTimeStamp as Finished | table OrderId  Started Finished
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And for the count, i have this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* sourcetype=C | stats count by OrderId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So in both separate queries, the OrderId is present. So how can I combine these 2 separate queries into a single one?&lt;/P&gt;

&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 14:29:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434814#M124036</guid>
      <dc:creator>anjo5</dc:creator>
      <dc:date>2019-01-28T14:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: use stats within join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434815#M124037</link>
      <description>&lt;P&gt;you ca use append before your third query&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 18:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434815#M124037</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-01-28T18:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: use stats within join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434816#M124038</link>
      <description>&lt;P&gt;Hi @anjo5 &lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* sourcetype=B 
| `Renaming` 
| eval Finished = MessageTimeStamp 
| fields Finished OrderId 
| append 
    [ search index=* sourcetype=A 
    | `Renaming` 
    | eval Started = MessageTimeStamp 
    | fields Started OrderId] 
| append 
    [ search index=* sourcetype=C 
    | stats count as count by OrderId 
    | fields OrderId count] 
| stats values(Started) as Started values(Finished) as Finished by OrderId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 19:22:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434816#M124038</guid>
      <dc:creator>chrisyounger</dc:creator>
      <dc:date>2019-01-28T19:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: use stats within join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434817#M124039</link>
      <description>&lt;P&gt;I believe you don't need the join at all. Give this query a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* (sourcetype=A OR sourcetype=B OR sourcetype=C)
| `Renaming`
| eval Start=if(sourcetype="A",MessageTimeStamp,null())
| eval Finish=if(sourcetype="B",MessageTimeStamp,null())
| stats values(Start) as Start values(Finish) as Finish count(eval(sourcetype="C")) as count by OrderId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Jan 2019 20:03:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434817#M124039</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-01-28T20:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: use stats within join</title>
      <link>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434818#M124040</link>
      <description>&lt;P&gt;Awesome!&lt;BR /&gt;
Works indeed exactly as expected, and I like that this solution is indeed so much more simple than what I was trying. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 08:12:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/use-stats-within-join/m-p/434818#M124040</guid>
      <dc:creator>anjo5</dc:creator>
      <dc:date>2019-01-29T08:12:32Z</dc:date>
    </item>
  </channel>
</rss>

