<?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: Is there a Splunk search command opposite of Transpose, similar to tools like &amp;quot;crosstab&amp;quot; or &amp;quot;crosstable&amp;quot;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146204#M40819</link>
    <description>&lt;P&gt;@somesoni2,&lt;/P&gt;

&lt;P&gt;The following search - your answer, slightly tweaked - produces the desired result (on my system):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="steverimar" | eval temp=Name."#".Month."#".Year | fields temp Data* | untable temp data Value | rex field=temp "(?&amp;lt;Name&amp;gt;.*)#(?&amp;lt;Month&amp;gt;.*)#(?&amp;lt;Year&amp;gt;.*)" | eval Month=Month+tonumber(substr(data, 5))-1 | table Name Month Year Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To exclude the unwanted rows, I replaced your original:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields - Name Month Year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields temp Data*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To increment the Month values, I inserted:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval Month=Month+tonumber(substr(data, 5))-1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One thing I liked about your answer is that it didn't rely on the field names being &lt;CODE&gt;Data1&lt;/CODE&gt;, &lt;CODE&gt;Data2&lt;/CODE&gt;...&lt;/P&gt;

&lt;P&gt;But my tweaks rely on those names. Can you offer alternative tweaks to fix the nits without introducing this dependency?&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2016 06:38:35 GMT</pubDate>
    <dc:creator>Graham_Hanningt</dc:creator>
    <dc:date>2016-04-28T06:38:35Z</dc:date>
    <item>
      <title>Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146196#M40811</link>
      <description>&lt;P&gt;I have a data set that looks like this:&lt;/P&gt;

&lt;P&gt;Name, Month, Year, Data1, Data2, Data3, Data4, Data[x]&lt;BR /&gt;
Steve, 2,2015, 1,1,1,0,0&lt;/P&gt;

&lt;P&gt;Where the Month and Year field are essentially the start date and that date's value is Data1 and the following Data[x] fields are the next month sequentially. &lt;/P&gt;

&lt;P&gt;Is there a Splunk command that will create the following for me. Other tools call this a "crosstab" or "crosstable". It's basically the opposite of a transpose.&lt;/P&gt;

&lt;P&gt;Name,Month, Year, Value&lt;BR /&gt;
Steve, 2, 2015, 1&lt;BR /&gt;
Steve, 3, 2015, 1&lt;BR /&gt;
Steve, 4, 2015, 1&lt;BR /&gt;
Steve, 5, 2015, 0&lt;BR /&gt;
Steve, 6, 2015, 0&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2015 20:40:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146196#M40811</guid>
      <dc:creator>steverimar</dc:creator>
      <dc:date>2015-04-16T20:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146197#M40812</link>
      <description>&lt;P&gt;|transpose&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2015 20:43:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146197#M40812</guid>
      <dc:creator>aalanisr26</dc:creator>
      <dc:date>2015-04-16T20:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146198#M40813</link>
      <description>&lt;P&gt;Transpose isn't what I'm looking for. I'm looking to cross table or do the opposite essentially.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2015 21:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146198#M40813</guid>
      <dc:creator>steverimar</dc:creator>
      <dc:date>2015-04-16T21:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146199#M40814</link>
      <description>&lt;P&gt;Would you be able to provide the actual field names from your current result?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2015 21:24:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146199#M40814</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-04-16T21:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146200#M40815</link>
      <description>&lt;P&gt;I second the request from @somesoni2:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Would you be able to provide the actual field names from your current result?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The following solution is based on the specific field names that you cited: &lt;CODE&gt;Data1&lt;/CODE&gt;, &lt;CODE&gt;Data2&lt;/CODE&gt; ...&lt;/P&gt;

&lt;P&gt;This solution is deliberately designed to work for a variable number of Data fields.&lt;/P&gt;

&lt;P&gt;I started with the following input data, in JSON format: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  "Name": "Steve",
  "Month": 2,
  "Year": 2015,
  "Data1": 1,
  "Data2": 2,
  "Data3": 3,
  "Data4": 4,
  "Data5": 5
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For testing purposes, I deliberately specified unique values for each Data field.&lt;/P&gt;

&lt;P&gt;The following search string (with line breaks inserted for readability) generates the output that you specified (I ingested the input data as sourcetype "steverimar"):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=steverimar |
eval data_column_name="" |
foreach Data* [eval data_column_name=data_column_name + " &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"] |
makemv data_column_name |
mvexpand data_column_name |
eval Value=spath(_raw, data_column_name) |
eval month_offset=tonumber(substr(data_column_name, 5)) - 1 |
eval Month=Month+month_offset |
table Name, Month, Year, Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Line-by-line explanation:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;sourcetype=steverimar&lt;/CODE&gt;&lt;BR /&gt;
Get the matching events.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;eval data_column_name=""&lt;/CODE&gt;&lt;BR /&gt;
Create a new field named &lt;CODE&gt;data_column_name&lt;/CODE&gt;, and set its value to an empty string.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;foreach&lt;/CODE&gt;...&lt;BR /&gt;
For each field whose name starts with "Data", append the name of that field to the value of the &lt;CODE&gt;data_column_name&lt;/CODE&gt; field.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;makemv&lt;/CODE&gt;...&lt;BR /&gt;
Convert &lt;CODE&gt;data_column_name&lt;/CODE&gt; into a multivalue field.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;mvexpand&lt;/CODE&gt;...&lt;BR /&gt;
Expand the values of &lt;CODE&gt;data_column_name&lt;/CODE&gt; into separate events, one event for each value.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;eval Value&lt;/CODE&gt;...&lt;BR /&gt;
Create a new field named &lt;CODE&gt;Value&lt;/CODE&gt;, and set its value to the value of the field &lt;EM&gt;whose name matches the value of the &lt;CODE&gt;data_column_name&lt;/CODE&gt; field&lt;/EM&gt;. For example, if the value of the &lt;CODE&gt;data_column_name&lt;/CODE&gt; field is "Data1", then set the value of the &lt;CODE&gt;Value&lt;/CODE&gt; field to the value of the &lt;CODE&gt;Data1&lt;/CODE&gt; field ("1").&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;eval month_offset&lt;/CODE&gt;...&lt;BR /&gt;
Create a new field name &lt;CODE&gt;month_offset&lt;/CODE&gt;, and set its value to the numeric suffix of the value of the &lt;CODE&gt;data_column_name&lt;/CODE&gt; field, minus 1.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;eval Month&lt;/CODE&gt;...&lt;BR /&gt;
Add the &lt;CODE&gt;month_offset&lt;/CODE&gt; to the value of the &lt;CODE&gt;Month&lt;/CODE&gt; field. (You could merge this step with the previous step. I kept them separate here for clarity.)&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;&lt;CODE&gt;table&lt;/CODE&gt;...&lt;BR /&gt;
Transform the search results (for display in the Statistics tab), limited to the fields that we want in our final results.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The technique used in steps 2 to 6 is described in the Splunk docs topic "&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/Search/Chartmultipledataseries"&gt;Build a chart of multiple data series&lt;/A&gt;".&lt;/P&gt;

&lt;P&gt;Here's a screenshot of the results in the Statistics tab of Splunk Web (Splunk Enterprise 6.4):&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/317i9FF1F7EEAF4E6E01/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;It occurs to me that this solution might not be exactly what you need, because your actual column names might not be &lt;CODE&gt;Data1&lt;/CODE&gt;, &lt;CODE&gt;Data2&lt;/CODE&gt;, etc., but this solution matches the column names that you specified in your question.&lt;/P&gt;

&lt;P&gt;I have not made the search string "smart" enough to increment the year if the month number is greater than 12. That would be easy to do.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2016 06:22:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146200#M40815</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-27T06:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146201#M40816</link>
      <description>&lt;P&gt;I would welcome alternatives to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval Value=spath(_raw, data_column_name)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That is:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;A field (in this example, &lt;CODE&gt;data_column_name&lt;/CODE&gt;) contains the name of another field.&lt;/LI&gt;
&lt;LI&gt;You want to get the value of that other field, and use it to set the value of a third field (in this example, &lt;CODE&gt;Value&lt;/CODE&gt;).&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 27 Apr 2016 06:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146201#M40816</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-27T06:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146202#M40817</link>
      <description>&lt;P&gt;This should do the trick&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your current search |  veal temp=Name."#".Month."#".Year | fields - Name Month Year | untable temp data Value | rex field=temp "(?&amp;lt;Name&amp;gt;.*)#(?&amp;lt;Month&amp;gt;.*)#(?&amp;lt;Year&amp;gt;.*)" | table Name Month Year Value
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 02:30:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146202#M40817</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-04-28T02:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146203#M40818</link>
      <description>&lt;P&gt;Nice! I learned some new tricks from your search string, thanks.&lt;/P&gt;

&lt;P&gt;I like your answer better than mine in several ways; for one, it's more concise.&lt;/P&gt;

&lt;P&gt;On my system, with the "test" event I described in my answer, the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="steverimar" | eval temp=Name."#".Month."#".Year | fields - Name Month Year | untable temp data Value | rex field=temp "(?&amp;lt;Name&amp;gt;.*)#(?&amp;lt;Month&amp;gt;.*)#(?&amp;lt;Year&amp;gt;.*)" | table Name Month Year Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;produces the following results (as displayed on the Statistics tab):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Name   Month      Year                                                     Value
Steve      2      2015                                                         1
Steve      2      2015                                                         2
Steve      2      2015                                                         3
Steve      2      2015                                                         4
Steve      2      2015                                                         5
Steve      2      2015                                            localhost:8088
Steve      2      2015                                                      test
Steve      2      2015                                                         1
Steve      2      2015        {"":_"",_"":_,_"":_,_"":_,_"":_,_"":_,_"":_,_"":_}
Steve      2      2015                                                  http:GXH
Steve      2      2015                                                steverimar
Steve      2      2015                                                      MYPC
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(I wish this forum supported table formatting. Does it? I've tried GitHub-flavored Markdown table formatting: nope. And HTML table, tr, and td tags get "sanitized" away.)&lt;/P&gt;

&lt;P&gt;Some nits:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;The results include not just the desired &lt;CODE&gt;Data1&lt;/CODE&gt;, &lt;CODE&gt;Data2&lt;/CODE&gt;... values, but also the values of the following fields: &lt;CODE&gt;host&lt;/CODE&gt;, &lt;CODE&gt;index&lt;/CODE&gt;, &lt;CODE&gt;linecount&lt;/CODE&gt;, &lt;CODE&gt;punct&lt;/CODE&gt;, &lt;CODE&gt;source&lt;/CODE&gt;, &lt;CODE&gt;sourcetype&lt;/CODE&gt;, &lt;CODE&gt;splunk_server&lt;/CODE&gt;. (Or is this my problem; Splunk behavior that I can change on my system?)&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;The Month column has the same value (2) in every row, whereas, according to the question, the value should increment by 1 after each row, starting from the value of the original Month field: 2, 3, 4, 5, 6.&lt;/LI&gt;
&lt;/UL&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 28 Apr 2016 06:19:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146203#M40818</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-28T06:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a Splunk search command opposite of Transpose, similar to tools like "crosstab" or "crosstable"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146204#M40819</link>
      <description>&lt;P&gt;@somesoni2,&lt;/P&gt;

&lt;P&gt;The following search - your answer, slightly tweaked - produces the desired result (on my system):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="steverimar" | eval temp=Name."#".Month."#".Year | fields temp Data* | untable temp data Value | rex field=temp "(?&amp;lt;Name&amp;gt;.*)#(?&amp;lt;Month&amp;gt;.*)#(?&amp;lt;Year&amp;gt;.*)" | eval Month=Month+tonumber(substr(data, 5))-1 | table Name Month Year Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To exclude the unwanted rows, I replaced your original:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields - Name Month Year
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields temp Data*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To increment the Month values, I inserted:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval Month=Month+tonumber(substr(data, 5))-1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One thing I liked about your answer is that it didn't rely on the field names being &lt;CODE&gt;Data1&lt;/CODE&gt;, &lt;CODE&gt;Data2&lt;/CODE&gt;...&lt;/P&gt;

&lt;P&gt;But my tweaks rely on those names. Can you offer alternative tweaks to fix the nits without introducing this dependency?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 06:38:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-Splunk-search-command-opposite-of-Transpose-similar/m-p/146204#M40819</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2016-04-28T06:38:35Z</dc:date>
    </item>
  </channel>
</rss>

