<?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 rewite a query to change the columns to rows and the rows to columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435607#M124203</link>
    <description>&lt;P&gt;Thanks a lot for your response. This would work for me. &lt;/P&gt;</description>
    <pubDate>Thu, 30 Aug 2018 10:00:51 GMT</pubDate>
    <dc:creator>sangs8788</dc:creator>
    <dc:date>2018-08-30T10:00:51Z</dc:date>
    <item>
      <title>How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435601#M124197</link>
      <description>&lt;P&gt;How to convert below query such that rows are converted to columns&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=data earliest=-1w@w latest=now |eval requestcount=1 | timechart per_second(requestcount) AS RequestPerSec
 | eventstats max(RequestPerSec) as peakRequestPerSec | timechart span=1w avg(RequestPerSec) as avgRequestPerSec max(RequestPerSec) as peakRequestPerSec p99(RequestPerSec) as p95RequestPerSec
 | fieldformat peakTime=strftime(peakTime,"%m/%y %H:%M") | eval avgRequestPerSec=round(avgRequestPerSec,2) | eval peakRequestPerSec=round(peakRequestPerSec,2)| eval p95RequestPerSec=round(p95RequestPerSec,2)|rename avgRequestPerSec as "Average Requests/Sec" peakRequestPerSec as "Max Requests/Sec" p95RequestPerSec as "P95 Requests/Sec"  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And also have an additional column added to the converted table which is to calculate/show the Percentage of increase/decrease compared to previous week data? Please let me know.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 04:58:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435601#M124197</guid>
      <dc:creator>sangs8788</dc:creator>
      <dc:date>2018-08-30T04:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435602#M124198</link>
      <description>&lt;P&gt;@sangs8788,&lt;/P&gt;

&lt;P&gt;Please try below query..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=data earliest=-1w@w latest=now 
| eval requestcount=1 
| timechart per_second(requestcount) AS RequestPerSec
| eventstats max(RequestPerSec) as peakRequestPerSec 
| timechart span=1w avg(RequestPerSec) as avgRequestPerSec max(RequestPerSec) as peakRequestPerSec p99(RequestPerSec) as p95RequestPerSec
| fieldformat peakTime=strftime(peakTime,"%m/%y %H:%M") 
| eval avgRequestPerSec=round(avgRequestPerSec,2) 
| eval peakRequestPerSec=round(peakRequestPerSec,2)
| eval p95RequestPerSec=round(p95RequestPerSec,2)

| eval group=avgRequestPerSec."#".peakRequestPerSec | chart Count as check over group by p95RequestPerSec | rex field=group "(?&amp;lt;avgRequestPerSec&amp;gt;[^#]+)#(?&amp;lt;peakRequestPerSec&amp;gt;[^#]+)") | fields - group

| table avgRequestPerSec peakRequestPerSec p95RequestPerSec 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;refer below answer also &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/467941/how-to-convert-partial-rows-into-columns-1.html"&gt;https://answers.splunk.com/answers/467941/how-to-convert-partial-rows-into-columns-1.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks ..&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 05:19:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435602#M124198</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2018-08-30T05:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435603#M124199</link>
      <description>&lt;P&gt;This doesnt work since it also again gives me the Avg,Peak &amp;amp; p95 as columns. I need it in below format&lt;/P&gt;

&lt;P&gt;Group | 12-08-2018 | 05-08-2018&lt;BR /&gt;
AvgRequestPerSec | 34 |65&lt;BR /&gt;
MaxRequestPerSec | 20 |99&lt;BR /&gt;
P95RequestPerSec | 19 | 50&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 06:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435603#M124199</guid>
      <dc:creator>sangs8788</dc:creator>
      <dc:date>2018-08-30T06:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435604#M124200</link>
      <description>&lt;P&gt;@sangs8788 add the following to your existing query (PS: Time needs to be formatted as String time in YYYY-mm-dd for sorting of date columns):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
| eval Time=strftime(_time,"%Y-%m-%d")
| fields - _*
| transpose header_field="Time" column_name="Group"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 07:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435604#M124200</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-30T07:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435605#M124201</link>
      <description>&lt;P&gt;Perfect. Thanks. This will do. But again, if i have to calculate the percentage of increase or decrease between two dates  it has to be done after the transpose isnt it ?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 07:42:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435605#M124201</guid>
      <dc:creator>sangs8788</dc:creator>
      <dc:date>2018-08-30T07:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435606#M124202</link>
      <description>&lt;P&gt;@sangs8788 , yes but if you want to further calculations you can give your Columns with Date static names like &lt;CODE&gt;Last Week&lt;/CODE&gt; and &lt;CODE&gt;Current Week&lt;/CODE&gt; Following is a run anywhere example based on Splunk's _internal index&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal earliest=-1w@w latest=now 
| eval requestcount=1 
| timechart per_second(requestcount) AS RequestPerSec 
| eventstats max(RequestPerSec) as peakRequestPerSec 
| bin _time span=1w 
| eval Time=strftime(_time,"%Y-%m-%d") 
| chart avg(RequestPerSec) as avgRequestPerSec max(RequestPerSec) as peakRequestPerSec p99(RequestPerSec) as p95RequestPerSec by Time 
| fieldformat peakTime=strftime(peakTime,"%m/%y %H:%M") 
| eval avgRequestPerSec=round(avgRequestPerSec,2) 
| eval peakRequestPerSec=round(peakRequestPerSec,2) 
| eval p95RequestPerSec=round(p95RequestPerSec,2) 
| rename avgRequestPerSec as "Average Requests/Sec" peakRequestPerSec as "Max Requests/Sec" p95RequestPerSec as "P95 Requests/Sec"
| streamstats count as sno
| eval Time=sno
| fields - _* sno
| transpose header_field="Time" column_name="Group"
| rename "1" as "Last Week", "2" as "Current Week"
| eval rate=round((('Current Week'-'Last Week')/'Current Week')*100,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Aug 2018 09:11:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435606#M124202</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-30T09:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to rewite a query to change the columns to rows and the rows to columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435607#M124203</link>
      <description>&lt;P&gt;Thanks a lot for your response. This would work for me. &lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 10:00:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rewite-a-query-to-change-the-columns-to-rows-and-the-rows/m-p/435607#M124203</guid>
      <dc:creator>sangs8788</dc:creator>
      <dc:date>2018-08-30T10:00:51Z</dc:date>
    </item>
  </channel>
</rss>

