<?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: Why is '&amp;quot;foreach&amp;quot; ingoring some columns in the calculation? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369842#M108934</link>
    <description>&lt;P&gt;seems like it could be a bug to report. it looks like it's taking the replaced colA as the divisor and then multiplying by 100, leaving it with the initial value. I don't know why colB and colC aren't doing it as well, though.&lt;/P&gt;

&lt;P&gt;to test, try creating a new column (colADup, or something) and do: &lt;CODE&gt;|eval colADup=colA|foreach * [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/colADup*100,2)]|fields - colADup&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 11:51:18 GMT</pubDate>
    <dc:creator>cmerriman</dc:creator>
    <dc:date>2017-03-22T11:51:18Z</dc:date>
    <item>
      <title>Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369841#M108933</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to calculate the ratio for all columns of a table compared to a specific column. So in the example below, just divide every column by colA. For some reason this does not work for all columns (colD is wrong), do you have any idea why?&lt;/P&gt;

&lt;P&gt;When I decide to write the calculated values into new columns instead of replacing them, it works &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/2658i1FE07A50D816D30A/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;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 11:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369841#M108933</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-03-22T11:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369842#M108934</link>
      <description>&lt;P&gt;seems like it could be a bug to report. it looks like it's taking the replaced colA as the divisor and then multiplying by 100, leaving it with the initial value. I don't know why colB and colC aren't doing it as well, though.&lt;/P&gt;

&lt;P&gt;to test, try creating a new column (colADup, or something) and do: &lt;CODE&gt;|eval colADup=colA|foreach * [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/colADup*100,2)]|fields - colADup&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 11:51:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369842#M108934</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-03-22T11:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369843#M108935</link>
      <description>&lt;P&gt;Creating a colADup column and using it in foreach works as well. I don't get it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 12:24:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369843#M108935</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-03-22T12:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369844#M108936</link>
      <description>&lt;P&gt;I think it's using the new '100' in colA in your original syntax when calculating colD, I'm just not sure why it doesn't do that for colB or colC.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 12:39:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369844#M108936</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-03-22T12:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369845#M108937</link>
      <description>&lt;P&gt;Because you have modified &lt;CODE&gt;colA&lt;/CODE&gt; in the middle of the work:  try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval _colA = colA | foreach * [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/_colA*100,2)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Fields that begin with underscores have several peculiarities, in particular these 2:&lt;BR /&gt;
    They are not shown on the 'Statistics&lt;CODE&gt;tab (except for&lt;/CODE&gt;&lt;EM&gt;time&lt;CODE&gt;),&lt;BR /&gt;
    They are not included in wildcards for fields (which is why you need to do things like&lt;/CODE&gt;index=* OR index=&lt;/EM&gt;*`).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 14:42:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369845#M108937</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-22T14:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Why is '"foreach" ingoring some columns in the calculation?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369846#M108938</link>
      <description>&lt;P&gt;That remark about fields whose names begin with underscores not being included in wildcards for fields is a life-saver. Is that documented anywhere?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 22:46:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-quot-foreach-quot-ingoring-some-columns-in-the/m-p/369846#M108938</guid>
      <dc:creator>helge</dc:creator>
      <dc:date>2018-09-11T22:46:49Z</dc:date>
    </item>
  </channel>
</rss>

