<?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: How to convert similar rows to adjacent column in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501171#M139559</link>
    <description>&lt;P&gt;hi nkumar,&lt;/P&gt;

&lt;P&gt;Please try the below solution.You could use the solution from "sort" in your actual query.&lt;BR /&gt;
If you want to compare start and end time between weeks - Add a step to increment the previous week's time to one week ahead.&lt;BR /&gt;
Please try and let us know.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |makeresults 
 | eval _raw="JOBS,DAY,COUNT,START,END
 abc.123a,TODAY,22,2019/11/04T02:04:05,2019/11/04T02:05:05
 axy.143b,TODAY,15,2019/11/04T04:05:05,2019/11/04T04:12:05
abc.144a,TODAY,23,2019/11/04T12:04:05,2019/11/04T12:14:05
abc.123a,LASTWEEK,12,2019/10/27T02:13:05,2019/10/27T02:15:05
axy.143b,LASTWEEK,53,2019/10/27T04:04:05,2019/10/27T04:05:05"
| multikv forceheader=1
| sort JOBS,DAY
|stats  list(COUNT) as TOTAL_COUNT,list(START) as START,list(END) as END BY JOBS
|where mvcount(TOTAL_COUNT)&amp;gt;1
|eval START_TIME=strptime(START,"%Y/%m/%dT%H:%M:%S"),END_TIME=strptime(END,"%Y/%m/%dT%H:%M:%S")
|eval TOTAL_COUNT_DIFF=abs(tonumber(mvindex(TOTAL_COUNT,0))-tonumber(mvindex(TOTAL_COUNT,1)))
|eval "START_TIME_DIFF in Minutes"=(tonumber(mvindex(START_TIME,1))-tonumber(mvindex(START_TIME,0)))/3600,"END_TIME_DIFF in Minutes"=(tonumber(mvindex(END_TIME,1))-tonumber(mvindex(END_TIME,0)))/3600
|table JOBS,TOTAL_COUNT_DIFF,"START_TIME_DIFF in Minutes","END_TIME_DIFF in Minutes"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Dec 2019 21:13:33 GMT</pubDate>
    <dc:creator>dindu</dc:creator>
    <dc:date>2019-12-04T21:13:33Z</dc:date>
    <item>
      <title>How to convert similar rows to adjacent column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501169#M139557</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=  abc source=xyz|table JOBS,DAY,COUNT,START,END
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is my current search which returns me result as:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;JOBS     DAY      COUNT    START                     END&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;abc.123a  TODAY    22     2019/11/04 02:04:05    2019/11/04 02:05:05&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;axy.143b  TODAY    15     2019/11/04 04:05:05    2019/11/04 04:12:05&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;abc.144a  TODAY    23     2019/11/04 12:04:05    2019/11/04 12:14:05&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;abc.123a  LASTWEEK  12     2019/10/27 02:13:05    2019/10/27 02:15:05&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;axy.143b  LASTWEEK  53     2019/10/27 04:04:05    2019/10/27 04:05:05&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I want to make &lt;CODE&gt;LASTWEEK&lt;/CODE&gt; data along with &lt;CODE&gt;TODAY&lt;/CODE&gt; data, so that further I can calculate the difference in &lt;CODE&gt;COUNT&lt;/CODE&gt; , &lt;CODE&gt;START&lt;/CODE&gt; and &lt;CODE&gt;END&lt;/CODE&gt;. AND for the null data either in TODAY or LASTWEEK it may be considered zero&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 15:32:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501169#M139557</guid>
      <dc:creator>nkumar6</dc:creator>
      <dc:date>2019-12-04T15:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert similar rows to adjacent column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501170#M139558</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval _raw="JOBS,DAY,COUNT,START,END
abc.123a,TODAY,22,2019/11/04T02:04:05,2019/11/04T02:05:05
axy.143b,TODAY,15,2019/11/04T04:05:05,2019/11/04T04:12:05
abc.144a,TODAY,23,2019/11/04T12:04:05,2019/11/04T12:14:05
abc.123a,LASTWEEK,12,2019/10/27T02:13:05,2019/10/27T02:15:05
axy.143b,LASTWEEK,53,2019/10/27T04:04:05,2019/10/27T04:05:05"
| multikv forceheader=1

| rename COMMENT AS "Everything above generates sample events; everything below is your solution"

| eval {DAY} = COUNT
| eventstats first(TODAY) AS TODAY first(LASTWEEK) AS LASTWEEK BY JOBS
| fillnull value=0 TODAY LASTWEEK
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:34:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501170#M139558</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-04T17:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert similar rows to adjacent column</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501171#M139559</link>
      <description>&lt;P&gt;hi nkumar,&lt;/P&gt;

&lt;P&gt;Please try the below solution.You could use the solution from "sort" in your actual query.&lt;BR /&gt;
If you want to compare start and end time between weeks - Add a step to increment the previous week's time to one week ahead.&lt;BR /&gt;
Please try and let us know.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |makeresults 
 | eval _raw="JOBS,DAY,COUNT,START,END
 abc.123a,TODAY,22,2019/11/04T02:04:05,2019/11/04T02:05:05
 axy.143b,TODAY,15,2019/11/04T04:05:05,2019/11/04T04:12:05
abc.144a,TODAY,23,2019/11/04T12:04:05,2019/11/04T12:14:05
abc.123a,LASTWEEK,12,2019/10/27T02:13:05,2019/10/27T02:15:05
axy.143b,LASTWEEK,53,2019/10/27T04:04:05,2019/10/27T04:05:05"
| multikv forceheader=1
| sort JOBS,DAY
|stats  list(COUNT) as TOTAL_COUNT,list(START) as START,list(END) as END BY JOBS
|where mvcount(TOTAL_COUNT)&amp;gt;1
|eval START_TIME=strptime(START,"%Y/%m/%dT%H:%M:%S"),END_TIME=strptime(END,"%Y/%m/%dT%H:%M:%S")
|eval TOTAL_COUNT_DIFF=abs(tonumber(mvindex(TOTAL_COUNT,0))-tonumber(mvindex(TOTAL_COUNT,1)))
|eval "START_TIME_DIFF in Minutes"=(tonumber(mvindex(START_TIME,1))-tonumber(mvindex(START_TIME,0)))/3600,"END_TIME_DIFF in Minutes"=(tonumber(mvindex(END_TIME,1))-tonumber(mvindex(END_TIME,0)))/3600
|table JOBS,TOTAL_COUNT_DIFF,"START_TIME_DIFF in Minutes","END_TIME_DIFF in Minutes"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 21:13:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-similar-rows-to-adjacent-column/m-p/501171#M139559</guid>
      <dc:creator>dindu</dc:creator>
      <dc:date>2019-12-04T21:13:33Z</dc:date>
    </item>
  </channel>
</rss>

