<?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: Set token from  table in Deployment Architecture</title>
    <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342518#M19396</link>
    <description>&lt;P&gt;Ideally you should have asked a new question for this. But here is the updated answer based on your new question (Please try out and upvote if this solves your issue):&lt;/P&gt;

&lt;P&gt;If you do not provide header_field to transpose function it gives them default names like &lt;STRONG&gt;"row 1", "row 2"... etc&lt;/STRONG&gt;. So you can run your query to count by week day and then sort them descending by count. Since you can read results only by one row you would need to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level="ERROR"
| stats count as CountByWeekDay by date_wday
| sort - CountByWeekDay
| eval CountByWeekDay= CountByWeekDay." (".date_wday.")"
| fields - date_wday
| transpose 7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can then use &lt;CODE&gt;$result.row 1$&lt;/CODE&gt;, &lt;CODE&gt;$result.row 2$&lt;/CODE&gt; etc to access the values. You can also add depends="$result.row 1$" etc to your HTML panel to hide them when they are not set. Otherwise, you will have to handle null results in your query itself to show zeros as the count fo a particular day. &lt;/P&gt;

&lt;P&gt;Following could be one of the approaches (run anywhere search based on Splunks _internal index). I am appending zero count rows for each of the week day and then picking max of the result for the weekday.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level="ERROR"
| stats count as CountByWeekDay by date_wday
| append [| makeresults
 | eval date_wday="sunday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="monday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="tuesday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="wednesday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="thursday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="friday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="saturday"
 | eval CountByWeekDay=0
 | fields - _time]
| stats max(CountByWeekDay) as CountByWeekDay by date_wday
| sort - CountByWeekDay
| eval CountByWeekDay= CountByWeekDay." (".date_wday.")"
| fields - date_wday
| transpose 7
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 Apr 2017 06:39:48 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-04-23T06:39:48Z</dc:date>
    <item>
      <title>Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342513#M19391</link>
      <description>&lt;P&gt;Hello Splunker's:&lt;/P&gt;

&lt;P&gt;I want to display the table result in a html And I have the problem:&lt;/P&gt;

&lt;P&gt;suppose search result:&lt;/P&gt;

&lt;P&gt;col1   col2&lt;BR /&gt;
 1         2&lt;BR /&gt;
then&lt;/P&gt;

&lt;P&gt;$result.col2$&lt;/P&gt;

&lt;P&gt;will set value "2" for "$row1_col2$"&lt;/P&gt;

&lt;P&gt;but if search result as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; col1  col2
 1       2
 3       4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;how could i get the value of "row2_col2" ?&lt;/P&gt;

&lt;P&gt;in Html i wante display &lt;BR /&gt;
col2&lt;BR /&gt;
2&lt;BR /&gt;
4&lt;/P&gt;

&lt;P&gt;Can you help please??&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 22:13:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342513#M19391</guid>
      <dc:creator>FredericA</dc:creator>
      <dc:date>2017-04-20T22:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342514#M19392</link>
      <description>&lt;P&gt;Updated: Answer based on details:&lt;/P&gt;

&lt;P&gt;You can either post-process for seven different searches for each week day as a row... Or else try to play around with transpose/xyseries commands to have the results displayed in a single row&lt;/P&gt;

&lt;P&gt;If you are performing stats count by Day, your transpose might look like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| stats count by Day
| transpose 7 header_field="Day" column_name="Day"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the Day field values are Monday, Tuesday etc. They will become your new FieldNames and you can perform $result.Monday$ etc. Try to run your search with transpose and you should get the idea!&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;@FredericA...&lt;CODE&gt;result.&amp;lt;fieldname&amp;gt;&lt;/CODE&gt; can only access field values from the first row or a search result with single row.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_tokens"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference#Search_event_tokens&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;How many rows do you expect your search to return and what is the kind of output that needs to be displayed in HTML? Would it still be tabular?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 06:01:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342514#M19392</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-21T06:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342515#M19393</link>
      <description>&lt;P&gt;Thank you for your reply,&lt;/P&gt;

&lt;P&gt;I have 7 rows (Monday-&amp;gt;sunday).&lt;/P&gt;

&lt;P&gt;The HTML output as an table.&lt;/P&gt;

&lt;P&gt;index=* | stats count by Day&lt;/P&gt;

&lt;P&gt;token is value and day.&lt;/P&gt;

&lt;P&gt;the Html is&lt;/P&gt;

&lt;P&gt;""&lt;BR /&gt;
""&lt;/P&gt;

&lt;P&gt;Day      ;     value&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 12:05:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342515#M19393</guid>
      <dc:creator>FredericA</dc:creator>
      <dc:date>2017-04-21T12:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342516#M19394</link>
      <description>&lt;P&gt;Thanks for the details. You should be able to pipe &lt;STRONG&gt;transpose&lt;/STRONG&gt; to your existing query and it will become single row with Field Names as the Name of the Week Day and Count as the Field Values. See my Answer above. Please up vote and accept if your issue is resolved.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 12:35:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342516#M19394</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-21T12:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342517#M19395</link>
      <description>&lt;P&gt;Thank you very much for your proposal, it works well.&lt;/P&gt;

&lt;P&gt;In case the day name depends on the result (sort -count limit=3 for example), I can apply this solution you have an idea.?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 20:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342517#M19395</guid>
      <dc:creator>FredericA</dc:creator>
      <dc:date>2017-04-22T20:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Set token from  table</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342518#M19396</link>
      <description>&lt;P&gt;Ideally you should have asked a new question for this. But here is the updated answer based on your new question (Please try out and upvote if this solves your issue):&lt;/P&gt;

&lt;P&gt;If you do not provide header_field to transpose function it gives them default names like &lt;STRONG&gt;"row 1", "row 2"... etc&lt;/STRONG&gt;. So you can run your query to count by week day and then sort them descending by count. Since you can read results only by one row you would need to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level="ERROR"
| stats count as CountByWeekDay by date_wday
| sort - CountByWeekDay
| eval CountByWeekDay= CountByWeekDay." (".date_wday.")"
| fields - date_wday
| transpose 7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can then use &lt;CODE&gt;$result.row 1$&lt;/CODE&gt;, &lt;CODE&gt;$result.row 2$&lt;/CODE&gt; etc to access the values. You can also add depends="$result.row 1$" etc to your HTML panel to hide them when they are not set. Otherwise, you will have to handle null results in your query itself to show zeros as the count fo a particular day. &lt;/P&gt;

&lt;P&gt;Following could be one of the approaches (run anywhere search based on Splunks _internal index). I am appending zero count rows for each of the week day and then picking max of the result for the weekday.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level="ERROR"
| stats count as CountByWeekDay by date_wday
| append [| makeresults
 | eval date_wday="sunday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="monday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="tuesday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="wednesday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="thursday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="friday"
 | eval CountByWeekDay=0
 | fields - _time]
| append [| makeresults
 | eval date_wday="saturday"
 | eval CountByWeekDay=0
 | fields - _time]
| stats max(CountByWeekDay) as CountByWeekDay by date_wday
| sort - CountByWeekDay
| eval CountByWeekDay= CountByWeekDay." (".date_wday.")"
| fields - date_wday
| transpose 7
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 06:39:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Set-token-from-table/m-p/342518#M19396</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-23T06:39:48Z</dc:date>
    </item>
  </channel>
</rss>

