<?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: Smooth values based on neighbouring bins in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Smooth-values-based-on-neighbouring-bins/m-p/2493537#M102334</link>
    <description>&lt;P&gt;Such approach must be slow because in each loop iteration is a table-load initialized which reads a larger resident-load with a heavy where-clause.&lt;/P&gt;
&lt;P&gt;Personally I would try a different way by accumulating the relevant neighbours with the help of interrecord-functions within an appropriate sorted resident load. Here a simplified example:&lt;/P&gt;
&lt;P&gt;load Key, Value, rangeavg(Value, previous(Value), peek('Value', -2)) as ValueAVG&lt;BR /&gt;resident Source order by Key;&lt;/P&gt;
&lt;P&gt;This means the essential part is the right ordering against one or several fields. Depending on the scenario it might be necessary to embed the accumulation-part within n (nested) if-loops to ensure that the interrecord-logic is restricted to the wanted areas and/or to run it twice - forwards and backwards - and/or to create n different avg-fields and/or to calculate the offset from the current value against the avg and/or to fetch outliers within further range-min/max and/or further grouping/flagging-fields or similar stuff.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2024 17:10:04 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2024-11-19T17:10:04Z</dc:date>
    <item>
      <title>Smooth values based on neighbouring bins</title>
      <link>https://community.qlik.com/t5/App-Development/Smooth-values-based-on-neighbouring-bins/m-p/2493526#M102329</link>
      <description>&lt;P&gt;I have a gridded map table produced by the GeoOperations binning function. However, some of the values in the map might be outliers relative to neighbours, so I have written a smoothing function in Qlik load editor to replace any outliers with the average value of the neighbouring bins. However, I have to run this function for hundreds of thousands of bins, multiplied by each dimension (product, date). How can I optimise the load script? It would be good to avoid the `for each` but I am not sure how.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-11-13 125002.png" style="width: 269px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174587i585E71F09926FBED/image-dimensions/269x273?v=v2" width="269" height="273" role="button" title="Screenshot 2024-11-13 125002.png" alt="Screenshot 2024-11-13 125002.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;(image illustrates how some values appear higher or lower than neighbouring bins. They look like dark and light spots. using a smoothing function, we can eliminate these outliers).&lt;/P&gt;
&lt;P&gt;binning_table_t2:&lt;BR /&gt;load *,&lt;BR /&gt;SubField(bin_id, '|', 2) as x,&lt;BR /&gt;SubField(bin_id, '|', 3) as y&lt;BR /&gt;resident binning_table_t&lt;BR /&gt;;&lt;BR /&gt;drop table binning_table_t;&lt;/P&gt;
&lt;P&gt;[t_distinct_bin_ids]:&lt;BR /&gt;load distinct bin_id as distinct_bin_ids resident binning_table_t2;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;// Create a temporary table with neighbor BinIds&lt;BR /&gt;neighbour_check:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;tmp_field&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;for each vBinId in FieldValueList('distinct_bin_ids')&lt;/P&gt;
&lt;P&gt;//Identify each surrounding neighbour for a bin id which has format 'R|X|Y'&lt;/P&gt;
&lt;P&gt;LET vX=SubField('$(vBinId)', '|', 2);&lt;BR /&gt;LET vY=SubField('$(vBinId)', '|', 3);&lt;BR /&gt;LET vYPlus1 = $(vY) + 1;&lt;BR /&gt;LET vYMinus1 = $(vY) - 1;&lt;BR /&gt;LET vXMinus1 = $(vX) - 1;&lt;BR /&gt;LET vXPlus1 = $(vX) + 1;&lt;BR /&gt;&lt;BR /&gt;[binning_table_t2_bin_id]:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;load date, product, avg_index_value resident binning_table_t2&lt;BR /&gt;WHERE &lt;BR /&gt;((x=$(vX) and y=$(vYPlus1)) or &lt;BR /&gt;(x=$(vX) and y=$(vYMinus1)) or &lt;BR /&gt;(x=$(vXMinus1) and y=$(vY)) or &lt;BR /&gt;(x=$(vXPlus1) and y=$(vY)) or&lt;BR /&gt;(x=$(vXMinus1) and y=$(vYPlus1)) or //top left&lt;BR /&gt;(x=$(vXPlus1) and y=$(vYPlus1)) or //top right&lt;BR /&gt;(x=$(vXMinus1) and y=$(vYMinus1)) or //bottom left&lt;BR /&gt;(x=$(vXPlus1) and y=$(vYMinus1))) //bottom right&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;trace $(vBinId);&lt;/P&gt;
&lt;P&gt;// Join the temporary table with your main data table&lt;BR /&gt;[neighbour_check]:&lt;BR /&gt;Concatenate(neighbour_check)&lt;BR /&gt;LOAD '$(vBinId)' as bin_id, product, date, avg(avg_index_value) as neighbouring_avg_index_value&lt;BR /&gt;resident binning_table_t2_bin_id&lt;BR /&gt;group by product, date&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;drop table binning_table_t2_bin_id;&lt;/P&gt;
&lt;P&gt;next vBinId&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample data :&lt;/P&gt;
&lt;P&gt;[binning_table_t]:&lt;/P&gt;
&lt;P&gt;load * inline [&lt;BR /&gt;bin_id , avg_index_value, date, product&lt;BR /&gt;R|114|838 , 0.60129568 , 30/10/2024 , apple&lt;BR /&gt;R|114|838 , 0.60129568 , 12/11/2024 , apple&lt;BR /&gt;R|114|839 , 0.47632898 , 12/11/2024 , apple&lt;BR /&gt;R|114|839 , 0.66667490883028 , 30/10/2024 , apple&lt;BR /&gt;R|114|843 , 0.55975765889839 , 12/11/2024 , apple&lt;BR /&gt;R|114|843 , 0.78789984277157 , 30/10/2024 , apple&lt;BR /&gt;R|114|844 , 0.67144721805877 , 12/11/2024 , apple&lt;BR /&gt;R|114|844 , 0.83291251451518 , 30/10/2024 , apple&lt;BR /&gt;R|114|846 , 0.5460232 , 12/11/2024 , apple&lt;BR /&gt;R|114|846 , 0.7981770082408 , 30/10/2024 , apple&lt;BR /&gt;R|114|847 , 0.63275596 , 12/11/2024 , apple&lt;BR /&gt;R|114|847 , 0.83393975481718 , 30/10/2024 , apple&lt;BR /&gt;R|115|838 , 0.50620004195143 , 12/11/2024 , apple&lt;BR /&gt;R|115|838 , 0.61589052 , 30/10/2024 , apple&lt;BR /&gt;R|115|839 , 0.54598076193291 , 12/11/2024 , apple&lt;BR /&gt;R|115|839 , 0.73205414 , 30/10/2024 , apple&lt;BR /&gt;R|115|842 , 0.70264421 , 12/11/2024 , apple&lt;BR /&gt;R|115|842 , 0.95325742113421 , 30/10/2024 , apple&lt;BR /&gt;R|115|843 , 0.65527531952943 , 12/11/2024 , apple&lt;BR /&gt;R|115|843 , 0.90651484 , 30/10/2024 , apple&lt;BR /&gt;R|115|844 , 0.61245206101525 , 12/11/2024 , apple&lt;BR /&gt;R|115|844 , 0.83911441747261 , 30/10/2024 , apple&lt;BR /&gt;R|115|846 , 0.75535312 , 12/11/2024 , apple&lt;BR /&gt;R|115|846 , 0.88929316987812 , 30/10/2024 , apple&lt;BR /&gt;R|115|847 , 0.6306660543884 , 12/11/2024 , apple&lt;BR /&gt;R|115|847 , 0.82988369243856 , 30/10/2024 , apple&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 16:19:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Smooth-values-based-on-neighbouring-bins/m-p/2493526#M102329</guid>
      <dc:creator>prayner</dc:creator>
      <dc:date>2024-11-19T16:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Smooth values based on neighbouring bins</title>
      <link>https://community.qlik.com/t5/App-Development/Smooth-values-based-on-neighbouring-bins/m-p/2493537#M102334</link>
      <description>&lt;P&gt;Such approach must be slow because in each loop iteration is a table-load initialized which reads a larger resident-load with a heavy where-clause.&lt;/P&gt;
&lt;P&gt;Personally I would try a different way by accumulating the relevant neighbours with the help of interrecord-functions within an appropriate sorted resident load. Here a simplified example:&lt;/P&gt;
&lt;P&gt;load Key, Value, rangeavg(Value, previous(Value), peek('Value', -2)) as ValueAVG&lt;BR /&gt;resident Source order by Key;&lt;/P&gt;
&lt;P&gt;This means the essential part is the right ordering against one or several fields. Depending on the scenario it might be necessary to embed the accumulation-part within n (nested) if-loops to ensure that the interrecord-logic is restricted to the wanted areas and/or to run it twice - forwards and backwards - and/or to create n different avg-fields and/or to calculate the offset from the current value against the avg and/or to fetch outliers within further range-min/max and/or further grouping/flagging-fields or similar stuff.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 17:10:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Smooth-values-based-on-neighbouring-bins/m-p/2493537#M102334</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2024-11-19T17:10:04Z</dc:date>
    </item>
  </channel>
</rss>

