<?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: Display multiple event duration as columns with sequence number in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164539#M46715</link>
    <description>&lt;P&gt;Let me just express my appreciation for your question. I love Splunk and sometimes challenging questions like this highlight the flexibility of the Search Processing Language (SPL). &lt;/P&gt;

&lt;P&gt;In this case we have taken your data set and modified the time stamps to ensure some things are clear. Most notably, the date in seconds has been modified to point out the following:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Total transaction time is 15 seconds&lt;/LI&gt;
&lt;LI&gt;Step A1 takes one (1) second &lt;/LI&gt;
&lt;LI&gt;Step A2 takes two (2) seconds &lt;/LI&gt;
&lt;LI&gt;Step A3 takes three (3) second &lt;/LI&gt;
&lt;LI&gt;Step B1 takes one (1) second &lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Step B2 takes two (2) seconds&lt;/P&gt;

&lt;P&gt;20150421 10:20:10 Step=stepStart, Tid=1234&lt;BR /&gt;
20150421 10:20:11 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:12 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:13 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:14 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:15 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:17 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:18 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:20 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:21 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:24 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:25 Step=stepEnd, Tid=1234&lt;BR /&gt;
Once we indexed the data, we used an in-line regular expression to obtain the type of the Step being taken.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="answers-1429817656" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| rex "Step=(?&lt;STEPA&gt;step[A])(?:Start|End)"&lt;BR /&gt;
  | rex "Step=(?&lt;STEPB&gt;step[B])(?:Start|End)"&lt;BR /&gt;
We then captured each transaction. Because the steps are sequential we used &lt;CODE&gt;reverse&lt;/CODE&gt; to reflect human ordering. We also assigned an ascending id using &lt;CODE&gt;accum&lt;/CODE&gt; to keep them in check for later.&lt;/STEPB&gt;&lt;/STEPA&gt;&lt;/P&gt;

&lt;P&gt;| transaction startswith="*Start" endswith="*End" &lt;BR /&gt;
| reverse &lt;BR /&gt;
| eval id=1 | accum id &lt;BR /&gt;
If you are trying this, at this point, you should see something like this:&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/34830-answers-1429817656-1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;From this point we manipulated the data to reflect your desired format. Firstly we reduced the data set to reflect the necessary fields in a nice table. Secondly we calculated the value for each step type and assign a variable. Here is that recipe:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats list(duration) AS duration list(StepA) AS StepA list(StepB) AS StepB list(Step) AS Step by Tid id 
| eval ida=if(isnotnull(StepA),1,null()) | accum ida 
| eval idb=if(isnotnull(StepB),1,null()) | accum idb 
| eval Step=if(isnotnull(StepA),StepA.ida,if(isnotnull(StepB),StepB.idb,Step)) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We were then inspired to  &lt;STRONG&gt;(╯°□°）╯︵ ┻━┻&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| xyseries Tid Step duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should provide you the following results:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/34831-answers-1429817656-2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I hope this helps you,&lt;/P&gt;

&lt;P&gt;--gc&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 19:37:10 GMT</pubDate>
    <dc:creator>Gilberto_Castil</dc:creator>
    <dc:date>2020-09-28T19:37:10Z</dc:date>
    <item>
      <title>Display multiple event duration as columns with sequence number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164538#M46714</link>
      <description>&lt;H2&gt;I'm trying to calculate duration of  stepAStart to stepAEnd and display them as columns with sequence number (eg StepA1, StepA2 ...). There is no steps between StepAStart and StepAEnd and the event pair may occur multiple times. The same for StepBStart and StepBEnd.&lt;/H2&gt;

&lt;P&gt;20150421 10:20:10 Step=stepStart, Tid=1234&lt;BR /&gt;
20150421 10:20:11 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:12 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:13 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:14 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:15 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:16 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:17 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:18 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:19 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:20 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:21 Step=stepEnd, Tid=1234&lt;/P&gt;

&lt;H2&gt;The result should be&lt;/H2&gt;

&lt;P&gt;Tid  StepStartEndDuration  StepA1  StepA2  StepA3  StepB1  StepB2 &lt;/P&gt;

&lt;H2&gt;1234 11 1 1 1 1 1&lt;/H2&gt;

&lt;P&gt;I tried the following but it returned multiple rows. How do I pivot the result? &lt;/P&gt;

&lt;P&gt;source="&lt;EM&gt;PerfMetrics&lt;/EM&gt;" &lt;BR /&gt;
|sort _time&lt;BR /&gt;
|delta _time as StepTime p=1&lt;BR /&gt;
|eval StepATime = if(Step="stepAEnd",StepTime,0)&lt;BR /&gt;
|eval StepBTime = if(Step="stepBEnd",StepTime,0)&lt;BR /&gt;
|transaction TId&lt;BR /&gt;
|eval StepStartEndDuration = duration &lt;BR /&gt;
|table StepStartEndDuration, StepATime, StepBTime&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 18:11:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164538#M46714</guid>
      <dc:creator>CatherineLiu007</dc:creator>
      <dc:date>2015-04-23T18:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Display multiple event duration as columns with sequence number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164539#M46715</link>
      <description>&lt;P&gt;Let me just express my appreciation for your question. I love Splunk and sometimes challenging questions like this highlight the flexibility of the Search Processing Language (SPL). &lt;/P&gt;

&lt;P&gt;In this case we have taken your data set and modified the time stamps to ensure some things are clear. Most notably, the date in seconds has been modified to point out the following:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Total transaction time is 15 seconds&lt;/LI&gt;
&lt;LI&gt;Step A1 takes one (1) second &lt;/LI&gt;
&lt;LI&gt;Step A2 takes two (2) seconds &lt;/LI&gt;
&lt;LI&gt;Step A3 takes three (3) second &lt;/LI&gt;
&lt;LI&gt;Step B1 takes one (1) second &lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Step B2 takes two (2) seconds&lt;/P&gt;

&lt;P&gt;20150421 10:20:10 Step=stepStart, Tid=1234&lt;BR /&gt;
20150421 10:20:11 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:12 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:13 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:14 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:15 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:17 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:18 Step=stepBStart, Tid=1234&lt;BR /&gt;
20150421 10:20:20 Step=stepBEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:21 Step=stepAStart, Tid=1234&lt;BR /&gt;
20150421 10:20:24 Step=stepAEnd, Tid=1234&lt;BR /&gt;
20150421 10:20:25 Step=stepEnd, Tid=1234&lt;BR /&gt;
Once we indexed the data, we used an in-line regular expression to obtain the type of the Step being taken.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="answers-1429817656" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;| rex "Step=(?&lt;STEPA&gt;step[A])(?:Start|End)"&lt;BR /&gt;
  | rex "Step=(?&lt;STEPB&gt;step[B])(?:Start|End)"&lt;BR /&gt;
We then captured each transaction. Because the steps are sequential we used &lt;CODE&gt;reverse&lt;/CODE&gt; to reflect human ordering. We also assigned an ascending id using &lt;CODE&gt;accum&lt;/CODE&gt; to keep them in check for later.&lt;/STEPB&gt;&lt;/STEPA&gt;&lt;/P&gt;

&lt;P&gt;| transaction startswith="*Start" endswith="*End" &lt;BR /&gt;
| reverse &lt;BR /&gt;
| eval id=1 | accum id &lt;BR /&gt;
If you are trying this, at this point, you should see something like this:&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/34830-answers-1429817656-1.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;From this point we manipulated the data to reflect your desired format. Firstly we reduced the data set to reflect the necessary fields in a nice table. Secondly we calculated the value for each step type and assign a variable. Here is that recipe:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats list(duration) AS duration list(StepA) AS StepA list(StepB) AS StepB list(Step) AS Step by Tid id 
| eval ida=if(isnotnull(StepA),1,null()) | accum ida 
| eval idb=if(isnotnull(StepB),1,null()) | accum idb 
| eval Step=if(isnotnull(StepA),StepA.ida,if(isnotnull(StepB),StepB.idb,Step)) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We were then inspired to  &lt;STRONG&gt;(╯°□°）╯︵ ┻━┻&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| xyseries Tid Step duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should provide you the following results:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/34831-answers-1429817656-2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I hope this helps you,&lt;/P&gt;

&lt;P&gt;--gc&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164539#M46715</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2020-09-28T19:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Display multiple event duration as columns with sequence number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164540#M46716</link>
      <description>&lt;P&gt;Thank you so much Gilberto. You have been great help. I'm really amazed what Splunk can do. I'm interested to learn more. Another question - when I have more than 10 occurrences of stepAs or stepBs I got column sequence as below&lt;BR /&gt;
Tid, StepB1, StepB10, StepB11, StepB2, ..., StepB9, Step (for StepStart/StepEnd), StepA1, StepA10, Step2,...,Step9. &lt;BR /&gt;
I added a sort before the last statement and that did not help. Is there a way to display  the columns like&lt;BR /&gt;
Tid, Step (for StepStart/StepEnd), StepA01, ...StepA11, StepB01, ..., StepB11&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2015 19:58:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164540#M46716</guid>
      <dc:creator>CatherineLiu007</dc:creator>
      <dc:date>2015-04-24T19:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Display multiple event duration as columns with sequence number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164541#M46717</link>
      <description>&lt;P&gt;The horizontal display of fields is governed by an alpha-numeric ordering. I would expect to see &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Tid, StepA1, StepA2 ... StepA11, StepB1 ... StepB9, StepStart StepEnd
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you reassign the field value prior to the &lt;CODE&gt;xyseries&lt;/CODE&gt; piece, then you can get it done. Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Step=if(isnotnull(StepA),StepA.ida,if(isnotnull(StepB),StepB.idb,Step))
| eval Step=if(Step=="stepEnd","StepStart/StepEnd",Step)
| xyseries Tid Step duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2015 21:05:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Display-multiple-event-duration-as-columns-with-sequence-number/m-p/164541#M46717</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2015-04-24T21:05:43Z</dc:date>
    </item>
  </channel>
</rss>

