<?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 use pivot (unpivot) command in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273974#M5241</link>
    <description>&lt;P&gt;I have replicated your sample table with a csv and developed the following, which I understand it's exactly what you are looking for based on your description:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv 
| untable ServerName Metrics Count
| rename Metrics as Column, ServerName as Rows
| sort -limit=0 Rows, Column
| eval Col_type = "Sub"
| appendpipe [ | stats sum(Count) as Count by Rows | eval Column = "Metric3" ]
| sort -limit=0 Rows, Column
| eventstats last(Column) as Parent_col by Rows
| eval Parent_col = if (Col_type = "Sub", Parent_col, null())
| table Column, Rows, Col_type, Parent_col, Count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output (see picture below):&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2419iC097ED0C75BD0D36/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;And this is the CSV I used:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ServerName,Metric1,Metric2 
Server1,1,0
Server2,1,1
Server3,1,1
Server4,0,1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 11:59:54 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2017-02-02T11:59:54Z</dc:date>
    <item>
      <title>How to use pivot (unpivot) command</title>
      <link>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273972#M5239</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;I have a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ServerName Metric1 Metric2 

Server1    1       0
Server2    1       1
Server3    1       1
Server4    0       1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And i need a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Column   Rows     Count

Metric1  Server1  1
Metric2  Server1  0
Metric1  Server2  1
Metric2  Server2  1
Metric1  Server3  1
Metric2  Server3  1
Metric1  Server4  0
Metric2  Server4  1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This was the simple case. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;The difficult case is:&lt;BR /&gt;
 i need a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Column   Rows      Col_type  Parent_col Count

Metric1  Server1   Sub       Metric3    1   
Metric2  Server1   Sub       Metric3    0
Metric3  Server1                        (Metric1+Metric2)
Metric1  Server2   Sub       Metric3    1
Metric2  Server2   Sub       Metric3    1
Metric3  Server2                        (Metric1+Metric2)
Metric1  Server3   Sub       Metric3    1
Metric2  Server3   Sub       Metric3    1
Metric3  Server3                        (Metric1+Metric2)
Metric1  Server4   Sub       Metric3    0
Metric2  Server4   Sub       Metric3    1
Metric3  Server4                        (Metric1+Metric2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks all!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 11:16:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273972#M5239</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2017-02-02T11:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use pivot (unpivot) command</title>
      <link>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273973#M5240</link>
      <description>&lt;P&gt;The community can best help you if you share some of the SPL commands you are using to generate the tables.  For example, are you actually using &lt;CODE&gt;pivot&lt;/CODE&gt; for this? Please share as much as possible.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 11:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273973#M5240</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-02-02T11:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use pivot (unpivot) command</title>
      <link>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273974#M5241</link>
      <description>&lt;P&gt;I have replicated your sample table with a csv and developed the following, which I understand it's exactly what you are looking for based on your description:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv 
| untable ServerName Metrics Count
| rename Metrics as Column, ServerName as Rows
| sort -limit=0 Rows, Column
| eval Col_type = "Sub"
| appendpipe [ | stats sum(Count) as Count by Rows | eval Column = "Metric3" ]
| sort -limit=0 Rows, Column
| eventstats last(Column) as Parent_col by Rows
| eval Parent_col = if (Col_type = "Sub", Parent_col, null())
| table Column, Rows, Col_type, Parent_col, Count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output (see picture below):&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2419iC097ED0C75BD0D36/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;And this is the CSV I used:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ServerName,Metric1,Metric2 
Server1,1,0
Server2,1,1
Server3,1,1
Server4,0,1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 11:59:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273974#M5241</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2017-02-02T11:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use pivot (unpivot) command</title>
      <link>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273975#M5242</link>
      <description>&lt;P&gt;Simply perfect!&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 13:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-to-use-pivot-unpivot-command/m-p/273975#M5242</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2017-02-02T13:50:54Z</dc:date>
    </item>
  </channel>
</rss>

