<?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: Special fillnull? Polulate null values with evaluated calculations in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401801#M116270</link>
    <description>&lt;P&gt;Below code is working and possibly the most efficient way of doing it. I'm accepting this as the correct answer but it was only because of @VatsalJagani 's answer that I was able to work it out.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="google_apis" source="https://www.googleapis.com/youtube" 
| timechart span=1h avg(subCount) by channel 
| fields - NULL 
| eventstats avg as a_*, stdev as s_* 
| eval rand = tostring("0." . random())
| eval rand =
    case(
    (rand &amp;gt; 0.00 AND rand &amp;lt; 0.16), -3,
    (rand &amp;gt; 0.16 AND rand &amp;lt; 0.32), -2,
    (rand &amp;gt; 0.32 AND rand &amp;lt; 0.48), -1,
    (rand &amp;gt; 0.48 AND rand &amp;lt; 0.64), 1,
    (rand &amp;gt; 0.64 AND rand &amp;lt; 0.80), 2,
    (rand &amp;gt; 0.80 AND rand &amp;lt; 1.00), 3,
    true(), 1) 
| foreach *
    [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = floor(ifnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 'a_&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' + ('s_&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' * rand), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] 
| fields - a_*, s_*, rand
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Jun 2019 07:14:59 GMT</pubDate>
    <dc:creator>morethanyell</dc:creator>
    <dc:date>2019-06-04T07:14:59Z</dc:date>
    <item>
      <title>Special fillnull? Polulate null values with evaluated calculations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401797#M116266</link>
      <description>&lt;P&gt;This is my code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="google_apis" source="https://www.googleapis.com/youtube"
 | timechart span=1h avg(subCount) by channel
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the results looks something like this&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/7139i8F09111772DE9260/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;Now, my problem is I can't seem to find a way on how to fill the null values with this formula:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"average of the field" + ("stdev of the field" * random(-3, 3))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My intention is to fill the null values with psuedo values that is 3 sigmas away (below or above) from the mean of the fields. I can get the avg and stdev by the &lt;CODE&gt;eventstats&lt;/CODE&gt; command. I can also get random number between -3 to 3. But I can't put them to the right place.&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 03:41:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401797#M116266</guid>
      <dc:creator>morethanyell</dc:creator>
      <dc:date>2019-06-03T03:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Special fillnull? Polulate null values with evaluated calculations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401798#M116267</link>
      <description>&lt;P&gt;Brute force method I used:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="google_apis" source="https://www.googleapis.com/youtube"
| timechart span=4h avg(subCount) by channel 
| fields - NULL 
| eval rand = tonumber("0." . random()) 
| eval rand =
    case(
    (rand &amp;gt; 0.00 AND rand &amp;lt; 0.16), -3,
    (rand &amp;gt; 0.16 AND rand &amp;lt; 0.32), -2,
    (rand &amp;gt; 0.32 AND rand &amp;lt; 0.48), -1,
    (rand &amp;gt; 0.48 AND rand &amp;lt; 0.64), 1,
    (rand &amp;gt; 0.64 AND rand &amp;lt; 0.80), 2,
    (rand &amp;gt; 0.80 AND rand &amp;lt; 1.00), 3,
    true(), 1) 
| eventstats avg as a_*, stdev as s_* 
| eval fnv = 'a_Making it happen Vlog' + (rand * 's_Making it happen Vlog') 
| eval "Making it happen Vlog" = floor(coalesce('Making it happen Vlog', fnv))
| eval fnv = 'a_The Juicy Vlog' + (rand * 's_The Juicy Vlog') 
| eval "The Juicy Vlog" = floor(coalesce('The Juicy Vlog', fnv))
| eval fnv = a_Morgz + (rand * s_Morgz) 
| eval Morgz = floor(coalesce(Morgz, fnv))
| eval fnv = a_MrBeast + (rand * s_MrBeast) 
| eval MrBeast = floor(coalesce(MrBeast, fnv))
| eval fnv = a_PewDiePie + (rand * s_PewDiePie) 
| eval PewDiePie = floor(coalesce(PewDiePie, fnv))
| eval fnv = a_Music + (rand * s_Music) 
| eval Music = floor(coalesce(Music, fnv))
| eval fnv = a_TSeries + (rand * s_TSeries) 
| eval TSeries = floor(coalesce(TSeries, fnv))
| fields - a_*, s_*, rand, fnv
| fields _time, *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jun 2019 02:33:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401798#M116267</guid>
      <dc:creator>morethanyell</dc:creator>
      <dc:date>2019-06-04T02:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Special fillnull? Polulate null values with evaluated calculations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401799#M116268</link>
      <description>&lt;P&gt;Hi @morethanyell,&lt;/P&gt;

&lt;P&gt;Check below query, it is really easy to understand whats happening.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval a="12", b="13" | append [| makeresults | eval a="13"] | append [| makeresults | eval b="3"] | append [| makeresults | eval a="2", b="1"] 
| appendpipe [| stats stdev(*) as stdev_*, avg(*) as avg_*
| foreach avg_* 
    [ eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=random() % 2 
    | eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=if(r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;==0,1,-1) 
    | eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=(random() % 4) * r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;
    | eval replace_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; = &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; + (stdev_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; * r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;)] | table replace_*]
| eventstats avg(replace_*) as replace_*
| foreach replace_* [eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=coalesce(&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]
| fields - replace_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above query will work, just replace first line with your query in question. &lt;STRONG&gt;Below is just understanding how the query is working&lt;/STRONG&gt;, if you are interested.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   | makeresults | eval a="12", b="13" | append [| makeresults | eval a="13"] | append [| makeresults | eval b="3"] | append [| makeresults | eval a="2", b="1"] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;is just to make similar results that you are having.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| appendpipe [| stats stdev(*) as stdev_*, avg(*) as avg_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Finds the stdev and avg.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| foreach avg_* 
    [ eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=random() % 2 
    | eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=if(r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;==0,1,-1) 
    | eval r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=(random() % 4) * r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;
    | eval replace_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; = &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; + (stdev_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; * r_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;)]  | table replace_*]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Finds the random number between (-3,3) and find the value that can be replaced where NULL is present. (replace_* fields)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats avg(replace_*) as replace_*
| foreach replace_* [eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=coalesce(&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Replace NULL values with replace_* field values with coalesce command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fields - replace_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Just to remove unnecessary field replace_*&lt;/P&gt;

&lt;P&gt;Hope this helps!!! BTW @morethanyell this is really nice question.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 06:12:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401799#M116268</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-04T06:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Special fillnull? Polulate null values with evaluated calculations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401800#M116269</link>
      <description>&lt;P&gt;Amazing work. But how can I capture the fields with spaces?&lt;BR /&gt;
EDIT: i worked it out. thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 06:34:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401800#M116269</guid>
      <dc:creator>morethanyell</dc:creator>
      <dc:date>2019-06-04T06:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Special fillnull? Polulate null values with evaluated calculations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401801#M116270</link>
      <description>&lt;P&gt;Below code is working and possibly the most efficient way of doing it. I'm accepting this as the correct answer but it was only because of @VatsalJagani 's answer that I was able to work it out.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="google_apis" source="https://www.googleapis.com/youtube" 
| timechart span=1h avg(subCount) by channel 
| fields - NULL 
| eventstats avg as a_*, stdev as s_* 
| eval rand = tostring("0." . random())
| eval rand =
    case(
    (rand &amp;gt; 0.00 AND rand &amp;lt; 0.16), -3,
    (rand &amp;gt; 0.16 AND rand &amp;lt; 0.32), -2,
    (rand &amp;gt; 0.32 AND rand &amp;lt; 0.48), -1,
    (rand &amp;gt; 0.48 AND rand &amp;lt; 0.64), 1,
    (rand &amp;gt; 0.64 AND rand &amp;lt; 0.80), 2,
    (rand &amp;gt; 0.80 AND rand &amp;lt; 1.00), 3,
    true(), 1) 
| foreach *
    [ eval "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" = floor(ifnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', 'a_&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' + ('s_&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' * rand), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'))] 
| fields - a_*, s_*, rand
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jun 2019 07:14:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Special-fillnull-Polulate-null-values-with-evaluated/m-p/401801#M116270</guid>
      <dc:creator>morethanyell</dc:creator>
      <dc:date>2019-06-04T07:14:59Z</dc:date>
    </item>
  </channel>
</rss>

