<?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: Unable to format chart field. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642976#M222708</link>
    <description>&lt;P&gt;There are uses of AS field name in chart command, just not with both over and by.&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2023 07:30:36 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-05-11T07:30:36Z</dc:date>
    <item>
      <title>Why am I unable to format chart field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642450#M222544</link>
      <description>&lt;P&gt;I'm attempting to chart a maximum duration by server and event_type, and I'd like to display the duration in HH:MM:SS format rather than a number of seconds. However, fieldformat doesn't seem to be applying the change to the assigned duration field. Is there a way to do this?&lt;/P&gt;
&lt;P&gt;Here's the command:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=s3batchtest eventcode Open | extract pairdelim="," kvdelim="=" | eval bDate=strptime(beginDate,"%Y-%m-%d %H:%M:%S") | eval lDate=strptime(lastDate,"%Y-%m-%d %H:%M:%S") | eval eventAge=lDate - bDate | chart max(eventAge) AS eventDuration by server eventCode limit=0 | fieldformat eventDuration=toString(eventDuration, "duration")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 10:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642450#M222544</guid>
      <dc:creator>MarcG</dc:creator>
      <dc:date>2023-05-08T10:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642462#M222551</link>
      <description>&lt;P&gt;Shouldn't it be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fieldformat eventDuration=strftime(eventDuration, "%H:%M:%S")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;instead? toString would have no way to know that you want it in HH:MM:SS.&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 05:33:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642462#M222551</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-05-06T05:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642531#M222561</link>
      <description>&lt;P&gt;toString(&amp;lt;value&amp;gt;, "duration") should format the time as HH:MM:SS, as described here -&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.1/SearchReference/ConversionFunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.1/SearchReference/ConversionFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 13:14:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642531#M222561</guid>
      <dc:creator>MarcG</dc:creator>
      <dc:date>2023-05-08T13:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642590#M222576</link>
      <description>&lt;P&gt;You are correct. (I didn't quite grasp "duration" as a directive.) &amp;nbsp;In that case, you'll need to examine content of bDate and lDate. &amp;nbsp;Is it possible that one of them is null? &amp;nbsp;Also examine values of beginDate and lastDate. &amp;nbsp;Is one of them null or multivalued?&lt;/P&gt;&lt;P&gt;Otherwise, it should function like the this emulation.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval beginDate = "2023-04-05 14:32:30", lastDate = "2023-04-10 06:20:11"
``` the above emulates index=s3batchtest eventcode Open | extract pairdelim="," kvdelim="=" ```
| eval bDate=strptime(beginDate,"%Y-%m-%d %H:%M:%S")
| eval lDate=strptime(lastDate,"%Y-%m-%d %H:%M:%S")
| eval eventAge=lDate - bDate
| chart max(eventAge) AS eventDuration
| fieldformat eventDuration=toString(eventDuration, "duration")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 05:30:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642590#M222576</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-05-09T05:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642690#M222595</link>
      <description>&lt;P&gt;While none of the dates in the actual log entries are null, it is the case that not all events occur on all servers, so there are some chart results that evaluate as null. Interestingly, if I follow the chart block with&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fillnull value=0&lt;/LI-CODE&gt;&lt;P&gt;then the empty chart entries are replaced with 0 as expected, but if I use&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fillnull value=0 eventDuration&lt;/LI-CODE&gt;&lt;P&gt;then they aren't, which leads me to believe that the chart results aren't actually being assigned to the eventDuration field, which would explain why my fieldformat command isn't working.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:11:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642690#M222595</guid>
      <dc:creator>MarcG</dc:creator>
      <dc:date>2023-05-09T15:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642775#M222629</link>
      <description>&lt;P&gt;I should have spotted this from your original illustration: &amp;nbsp;eventDuration doesn't exist as a field name in chart command; in other words, "AS eventDuration" may as well be omitted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart max(eventAge) AS eventDuration by server eventCode limit=0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;is equivalent to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart max(eventAge) over server by eventCode limit=0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output contains a field named "server", and multiple fields each named after one distinct eventCode. (You can see these headers in statistics table.) &amp;nbsp;Assuming that you don't have pure integer number as server name, you can do something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart max(eventDuration) over server by eventCode
| foreach *
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = if(isint(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), tostring(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "duration"), &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unlike fieldformat, after eval, you won't be able to use those values as numerals until you convert them back. &amp;nbsp;But fieldformat doesn't work in foreach.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 09:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642775#M222629</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-05-10T09:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642869#M222654</link>
      <description>&lt;P&gt;That's also interesting, since the spec for the chart command does say that you can assign the results of the aggregate to a field value using the AS command. However, I did try your suggestion, and after a few tweaks (refining the eval of eventAge to produce an integer instead of a float), the report is now providing the results I wanted. Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 15:12:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642869#M222654</guid>
      <dc:creator>MarcG</dc:creator>
      <dc:date>2023-05-10T15:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to format chart field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642976#M222708</link>
      <description>&lt;P&gt;There are uses of AS field name in chart command, just not with both over and by.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 07:30:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-am-I-unable-to-format-chart-field/m-p/642976#M222708</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-05-11T07:30:36Z</dc:date>
    </item>
  </channel>
</rss>

