<?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: Calculations where certain conditions are met - script or set expression? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Calculations-where-certain-conditions-are-met-script-or-set/m-p/2021058#M1222059</link>
    <description>&lt;P&gt;You can try this in the script.&lt;BR /&gt;With a join I add to every row the sum of the values with ID_LEVEL -1 and with MAN_ID equal to the ID of the row.&lt;/P&gt;
&lt;P&gt;LEFT JOIN (Table)&lt;BR /&gt;LOAD&lt;BR /&gt;ID_LEVEL -1 AS ID_LEVEL,&lt;BR /&gt;MAIN_ID AS ID,&lt;BR /&gt;SUM(VALUE) as VALUE_ID_LEVEL_MINUS_1&lt;BR /&gt;RESIDENT Table&lt;BR /&gt;group by ID_LEVEL, MAIN_ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jan 2023 12:11:34 GMT</pubDate>
    <dc:creator>maxgro</dc:creator>
    <dc:date>2023-01-02T12:11:34Z</dc:date>
    <item>
      <title>Calculations where certain conditions are met - script or set expression?</title>
      <link>https://community.qlik.com/t5/QlikView/Calculations-where-certain-conditions-are-met-script-or-set/m-p/2021044#M1222058</link>
      <description>&lt;P&gt;Hi all!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not been able to create a working logic to perform this calculation. To illustrate, here is an inline table as a simplified version of the problem:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table:&lt;/P&gt;
&lt;P&gt;LOAD * Inline [&lt;/P&gt;
&lt;P&gt;VALUE,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID_LEVEL,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MAIN_ID&lt;/P&gt;
&lt;P&gt;15 444,&amp;nbsp; &amp;nbsp; &amp;nbsp;5562,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5 584,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;132994,&amp;nbsp; &amp;nbsp; &amp;nbsp;1,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5562&lt;BR /&gt;2 172,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5564,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5562&lt;BR /&gt;2 136,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;171655,&amp;nbsp; &amp;nbsp; &amp;nbsp;1,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5562&lt;BR /&gt;935,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;260763,&amp;nbsp; &amp;nbsp; &amp;nbsp;1,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5562&lt;BR /&gt;337,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5563,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5562&lt;BR /&gt;1 880,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;139198,&amp;nbsp; &amp;nbsp; &amp;nbsp; 2,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;132994&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;So this is a "hierarchical" fact table and these VALUEs are in a relationship with each other based on the ID_LEVEL. The actual VALUE of the ID=5562 (ID_level=0) is 15444 - 5585 - 2172- 2136 - 935 - 337 = 4280, in other words,ID_LEVEL=0 - ID_LEVEL 1, where MAIN_ID equals ID. And this logic goes on so that the actual VALUE of&amp;nbsp; ID=132994 (ID_LEVEL=1 with a sub_ID) is&amp;nbsp;ID_LEVEL=1 -&amp;nbsp;ID_LEVEL=2&amp;nbsp;where MAIN_ID equals ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I would need a new column: ACTUAL_VALUE.&lt;/P&gt;
&lt;P&gt;I have ~1 million rows like this, so the logic should not be too heavy to calculate and that's why I'm reluctant to try any If() methods in the front-end. The back-end load can take resources though, so it is okay to be heavy there.&amp;nbsp; Any insights? Is it possible in script editor or should I try to work it out with set expressions?&amp;nbsp;It is okay to add columns if needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;English is not my main language so feel free to ask if I failed to explain it in a reasonable fashion.&lt;/P&gt;
&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 11:27:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculations-where-certain-conditions-are-met-script-or-set/m-p/2021044#M1222058</guid>
      <dc:creator>SamuliPeura</dc:creator>
      <dc:date>2023-01-02T11:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations where certain conditions are met - script or set expression?</title>
      <link>https://community.qlik.com/t5/QlikView/Calculations-where-certain-conditions-are-met-script-or-set/m-p/2021058#M1222059</link>
      <description>&lt;P&gt;You can try this in the script.&lt;BR /&gt;With a join I add to every row the sum of the values with ID_LEVEL -1 and with MAN_ID equal to the ID of the row.&lt;/P&gt;
&lt;P&gt;LEFT JOIN (Table)&lt;BR /&gt;LOAD&lt;BR /&gt;ID_LEVEL -1 AS ID_LEVEL,&lt;BR /&gt;MAIN_ID AS ID,&lt;BR /&gt;SUM(VALUE) as VALUE_ID_LEVEL_MINUS_1&lt;BR /&gt;RESIDENT Table&lt;BR /&gt;group by ID_LEVEL, MAIN_ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 12:11:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculations-where-certain-conditions-are-met-script-or-set/m-p/2021058#M1222059</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2023-01-02T12:11:34Z</dc:date>
    </item>
  </channel>
</rss>

