<?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 eval to rename a variable unter certain conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545536#M154548</link>
    <description>&lt;P&gt;Since you don't want the other fields, try the alternative solution with a fields command to limit the fields&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| xyseries OrderNr WeightTypeId Weight
| eval total='1'+'2'+'4'+'5'
| eval yield1='1'/total
| eval yield2='3'/total
| fields OrderNr yield1 yield2 total&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 26 Mar 2021 07:57:17 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2021-03-26T07:57:17Z</dc:date>
    <item>
      <title>How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545407#M154477</link>
      <description>&lt;P&gt;I have under each orderNr five different weights.&lt;/P&gt;&lt;P&gt;__________________________&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;Weight: 0.898&lt;SPAN&gt;, &lt;/SPAN&gt;WeightTypeId: 1, OrderNr: 8478&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;Weight: 0.094&lt;SPAN&gt;, &lt;/SPAN&gt;WeightTypeId: 2, OrderNr: 8478&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;Weight: 7.45&lt;SPAN&gt;, &lt;/SPAN&gt;WeightTypeId: 3,&amp;nbsp;OrderNr: 8478&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;Weight:&lt;/SPAN&gt; &lt;SPAN class="t"&gt;0.0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="t"&gt;WeightTypeId:&lt;/SPAN&gt; &lt;SPAN class="t"&gt;4,&amp;nbsp;OrderNr: 8478&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;Weight: 7.45&lt;SPAN&gt;, &lt;/SPAN&gt;WeightTypeId: 5,&amp;nbsp;OrderNr: 8478&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;...............................&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t"&gt;___________________________________&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I would like to calculate the total weight and the yields, which is calculated like this:&amp;nbsp;&lt;BR /&gt;Total:&amp;nbsp; Weight(WeightTypeID1) +&amp;nbsp;Weight(WeightTypeID2) +Weight(WeightTypeID4) +Weight(WeightTypeID5)&lt;BR /&gt;Yield1 = Weight (WeightTypeId 1)/ Total&lt;BR /&gt;Yield2=&amp;nbsp;Weight(WeightTypeID3)/Total&lt;/P&gt;&lt;P&gt;I am thinking of using eval to assign the Weight (under WeightTypeId1) to weight 1, weight 2, weight 3.... Then it is easy to do the calculations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;|Eval werigh1= if (WeightTypeId=1, Weight, 0). But somehow I feel this is not correct...&lt;/P&gt;&lt;P&gt;Can someone help me with that?&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 14:11:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545407#M154477</guid>
      <dc:creator>zoe</dc:creator>
      <dc:date>2021-03-25T14:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545409#M154479</link>
      <description>&lt;P&gt;It is on the right lines. Try:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval weight1=if(WeightTypeId=1,weight,null)
| eval weight2=if(WeightTypeId=2,weight,null)
| eval weight3=if(WeightTypeId=3,weight,null)
| eval weight4=if(WeightTypeId=4,weight,null)
| eval weight5=if(WeightTypeId=5,weight,null)
| stats values(*) as * by OrderNr
| eval total=weight1+weight2+weight4+weight5
| eval yield1=weight1/total
| eval yield2=weight3/total&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 14:19:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545409#M154479</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-25T14:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545416#M154482</link>
      <description>&lt;P&gt;Alternatively:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| xyseries OrderNr WeightTypeId Weight
| eval total='1'+'2'+'4'+'5'
| eval yield1='1'/total
| eval yield2='3'/total&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 14:48:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545416#M154482</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-25T14:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545530#M154545</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;for your help!I have three questions to your solution&lt;/P&gt;&lt;P&gt;1. I see you used 'null' instead '0', does it mean, when the condition is not fulfilled, the variable will have no value instead of '0'? I tried '0', it is not working.....&lt;/P&gt;&lt;P&gt;2. You put &lt;STRONG&gt;&lt;U&gt;| stats value(*) as * by OrderNr&lt;/U&gt;&lt;/STRONG&gt; before the rest of eval commands of 'total', 'yield1' and 'Yield2'. But if I put this stats command in the end, the result does not show 'total', 'yield1' and 'yeild2'? Why does the order matter?&lt;/P&gt;&lt;P&gt;3. In the end I just want to see sth like this&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 07:34:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545530#M154545</guid>
      <dc:creator>zoe</dc:creator>
      <dc:date>2021-03-26T07:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545532#M154546</link>
      <description>&lt;P&gt;sorry&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;, I sent the last message by mistake before finishing it. Now continues&lt;/P&gt;&lt;P&gt;3. in the end I woule like to see sth like this:&lt;/P&gt;&lt;P&gt;OrderNr&amp;nbsp; Yield1, Yield2, Total&lt;/P&gt;&lt;P&gt;Acutally thre are also some other varibles in each event. But what I see now is that all other vairlabes are also listed. weight 1, weight 2....... WeighTypeId...., time stamp.... hostname, source....., which I do not want to include in the result. I tried to use&amp;nbsp; &lt;STRONG&gt;|Stats Values(yield1) as yield1 by OrderNr&amp;nbsp;&lt;/STRONG&gt;, but it does not work. Can you help me with that?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 07:42:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545532#M154546</guid>
      <dc:creator>zoe</dc:creator>
      <dc:date>2021-03-26T07:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545534#M154547</link>
      <description>&lt;OL&gt;&lt;LI&gt;By using null instead of zero, the field is not present for the other events, so when the events are grouped together by OrderNr with the stats command, you don't get extra zeroes that you don't need&lt;/LI&gt;&lt;LI&gt;The order matter because it is the stats command that is collecting all the weights into one line so the calculation can be done&lt;/LI&gt;&lt;LI&gt;I am not sure what you want it to look like&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Did you try the alternative solution?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 07:52:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545534#M154547</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-26T07:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545536#M154548</link>
      <description>&lt;P&gt;Since you don't want the other fields, try the alternative solution with a fields command to limit the fields&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| xyseries OrderNr WeightTypeId Weight
| eval total='1'+'2'+'4'+'5'
| eval yield1='1'/total
| eval yield2='3'/total
| fields OrderNr yield1 yield2 total&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 26 Mar 2021 07:57:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545536#M154548</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-03-26T07:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545539#M154550</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;at the end of your first solution, I put&amp;nbsp;&lt;STRONG&gt;| table OrderNr total yield1 yield2&lt;/STRONG&gt;, then I can what I want to see. I hpe this is correct&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zoe_0-1616745711773.png" style="width: 500px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/13502i12C71FC65B0EC20A/image-dimensions/500x30?v=v2" width="500" height="30" role="button" title="zoe_0-1616745711773.png" alt="zoe_0-1616745711773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 08:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545539#M154550</guid>
      <dc:creator>zoe</dc:creator>
      <dc:date>2021-03-26T08:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use eval to rename a variable unter certain conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545540#M154551</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;this solution is great! the first time I have learned xyseries! Thank you a lot! I have learned a lot from you!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 08:03:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-eval-to-rename-a-variable-unter-certain-conditions/m-p/545540#M154551</guid>
      <dc:creator>zoe</dc:creator>
      <dc:date>2021-03-26T08:03:51Z</dc:date>
    </item>
  </channel>
</rss>

