<?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 Calculating data with multiple transactions per order in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310009#M93014</link>
    <description>&lt;P&gt;Hi, I have the following data with the following columns, OrderNo, Transaction Start, Transaction Stop.  I wrote a search by OrderNo to get the time difference for each order.  The problem is that Order Number 333 below has multiple transactions and I need to calculate based on every 2 lines of data based on OrderNo.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/192180-1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;It works fine until I get to Orders that have multiple transactions.&lt;/P&gt;

&lt;P&gt;index=myindex source=mysource Service=myservice OrderNo=*&lt;BR /&gt;
|eval start_time = strrptime(transaction_start, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval stop_time = strptime(transaction_stop, "%Y-%m-%d %H:%M:%S") &lt;BR /&gt;
| stats earliest(start_time) as start_time earliest(stop_time) as stop_time by OrderNo, Service &lt;BR /&gt;
| eval duration=tostring(stop_time-start_time) &lt;BR /&gt;
| stats mean(duration) as avg_duration by Service &lt;BR /&gt;
| table Service, avg_duration&lt;/P&gt;

&lt;P&gt;Is it possible to read through one OrderNo to split it up into several transactions.  It's obvious I shouldn't be using earliest but I just realized some of the orders have multiple transactions and after searching and coming up empty I ended up here.  &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 13:32:06 GMT</pubDate>
    <dc:creator>timm747747</dc:creator>
    <dc:date>2020-09-29T13:32:06Z</dc:date>
    <item>
      <title>Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310009#M93014</link>
      <description>&lt;P&gt;Hi, I have the following data with the following columns, OrderNo, Transaction Start, Transaction Stop.  I wrote a search by OrderNo to get the time difference for each order.  The problem is that Order Number 333 below has multiple transactions and I need to calculate based on every 2 lines of data based on OrderNo.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/192180-1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;It works fine until I get to Orders that have multiple transactions.&lt;/P&gt;

&lt;P&gt;index=myindex source=mysource Service=myservice OrderNo=*&lt;BR /&gt;
|eval start_time = strrptime(transaction_start, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval stop_time = strptime(transaction_stop, "%Y-%m-%d %H:%M:%S") &lt;BR /&gt;
| stats earliest(start_time) as start_time earliest(stop_time) as stop_time by OrderNo, Service &lt;BR /&gt;
| eval duration=tostring(stop_time-start_time) &lt;BR /&gt;
| stats mean(duration) as avg_duration by Service &lt;BR /&gt;
| table Service, avg_duration&lt;/P&gt;

&lt;P&gt;Is it possible to read through one OrderNo to split it up into several transactions.  It's obvious I shouldn't be using earliest but I just realized some of the orders have multiple transactions and after searching and coming up empty I ended up here.  &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:32:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310009#M93014</guid>
      <dc:creator>timm747747</dc:creator>
      <dc:date>2020-09-29T13:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310010#M93015</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex source=mysource Service=myservice OrderNo=*
|eval start_time = strrptime(transaction_start, "%Y-%m-%d %H:%M:%S")
| eval stop_time = strptime(transaction_stop, "%Y-%m-%d %H:%M:%S") 
| streamstats last(stop_time) as stop_time by OrderNo, Service
| search start_time="*"
| eval duration=tostring(stop_time-start_time) 
| eventstats mean(duration) as avg_duration by Service 
| table Service, avg_duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2017 17:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310010#M93015</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-04T17:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310011#M93016</link>
      <description>&lt;P&gt;If you can make the assumption that the multiple transactions will never be overlapping, or interleaving,   then you can use streamstats to make yourself an additional field that can supply the extra distinctness.   Note the streamstats I've added in line 4, and the extra "transaction_count" field I added to the group by clause in the stats command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex source=mysource Service=myservice OrderNo=*
| eval start_time = strrptime(transaction_start, "%Y-%m-%d %H:%M:%S")
| eval stop_time = strptime(transaction_stop, "%Y-%m-%d %H:%M:%S") 
| streamstats dc(start_time) as transaction_count by OrderNo
| stats earliest(start_time) as start_time earliest(stop_time) as stop_time by OrderNo, transaction_count, Service 
| eval duration=tostring(stop_time-start_time) 
| stats mean(duration) as avg_duration by Service 
| table Service, avg_duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the above,  the &lt;CODE&gt;| streamstats dc(start_time) as transaction_count by OrderNo&lt;/CODE&gt; command sneaks in just before the main stats,  and it will paint a little integer onto each transaction.  For the simple ones they'll each just get a "1" for that integer.  But the ones with the multiple transaction will get a different integer for each transactoin. &lt;BR /&gt;
Of course, if the multiple transactions for a given OrderNo can get interleaved,  then this will become a mess.   (You could even then craft an explicit search to test whether that assumption is true,  possibly even run that second search for a while as an alert if you're paranoid about it. )&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 17:23:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310011#M93016</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2017-04-04T17:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310012#M93017</link>
      <description>&lt;P&gt;can you try using &lt;CODE&gt;streamstats&lt;/CODE&gt; and &lt;CODE&gt;filldown&lt;/CODE&gt; to get them into one line?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex source=mysource Service=myservice OrderNo=*
|eval start_time = strrptime(transaction_start, "%Y-%m-%d %H:%M:%S")
| eval stop_time = strptime(transaction_stop, "%Y-%m-%d %H:%M:%S") 
| filldown transaction_start
| streamstats count by OrderNo transaction_start
| search count=2
| eval duration=tostring(stop_time-start_time) 
| stats mean(duration) as avg_duration by Service 
| table Service, avg_duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2017 17:31:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310012#M93017</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-04-04T17:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310013#M93018</link>
      <description>&lt;P&gt;Thank you that worked!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 12:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310013#M93018</guid>
      <dc:creator>timm747747</dc:creator>
      <dc:date>2017-04-05T12:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating data with multiple transactions per order</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310014#M93019</link>
      <description>&lt;P&gt;Note that for your OrderNo values that have multiple transactions,  this answer is going to calculate a single duration that is from the start of the Order's earliest transaction to the end of the latest transaction.   it will factor that single large duration into the later average, rather than factoring in the individual transaction durations.   But if that is OK or even desired, then indeed this approach is simpler. &lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 16:47:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-data-with-multiple-transactions-per-order/m-p/310014#M93019</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2017-04-05T16:47:14Z</dc:date>
    </item>
  </channel>
</rss>

