<?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: Script Sum If With Groups Causes Duplication in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670231#M449408</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/54672"&gt;@ben2r&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Left join performance issues are fairly common and there's a few ways around them. The first thing I like to consider is "do I really need to join these tables". The Qlik engine is really optimised to work in a different way, if in creating your mini sum tables it sounds like you'll have associations available to you on client_key, you could just leave them be. There's a whole lot of data modelling religious arguments that might be started with what I've just said but I think it's worth thinking about, there's plenty of evidence in articles here on community that it will perform well and meet your needs.&lt;/P&gt;&lt;P&gt;Leaving the above aside, there are various options discussed here on community if you search on "left join performance" (I prefer to just search in Google prefixing my search with "Qlik"). I'd take a look at the Keep (there is a left keep) function and mapping load, either of which might meet your needs. There's a telling line in the help for the Keep statement: "&lt;SPAN&gt;Explicit joins should therefore generally be avoided in&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="CommonComponentsQlik Sense"&gt;Qlik Sense&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;scripts".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not suggesting an explicit solution here as everyone's data and environment is different and you might need to test a few things for yourself to see what your performance is like. I also don't know how fixed you are on having to have everything in the one table.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rod&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 22:00:58 GMT</pubDate>
    <dc:creator>Rodj</dc:creator>
    <dc:date>2020-01-28T22:00:58Z</dc:date>
    <item>
      <title>Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670209#M449406</link>
      <description>&lt;P&gt;I have a large table of transactional like data (15m rows) over which I am trying to efficiently pre-calculate some of the client level sum fields I want to use in the dashboard.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are broadly 3 sums I am trying to do, sum where product = A, sum where product = B and sum where product = A or B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only way I have been able to get this to work so far is to create 3 loads of the master table, saving the result in a results table. This is one for product A, one for B and one for A or B. Example code is below (for A and B):&lt;/P&gt;&lt;P&gt;LOAD&lt;BR /&gt;%CLIENT_KEY,&lt;BR /&gt;SUM(AMOUNT) as AFIN_iCNR_2019&lt;BR /&gt;RESIDENT FACT_CROSS //This is the source table&lt;BR /&gt;WHERE ASPECT = 'CNR' AND FACT_YEAR = '2019' AND (%PROD_LINE = 'PROD A' OR %PROD_LINE = 'PROD B')&lt;BR /&gt;GROUP BY %CLIENT_KEY;&lt;/P&gt;&lt;P&gt;I repeat this for the other 2 products individually and left join the back to this table to give one table with 3 new sum columns.&lt;/P&gt;&lt;P&gt;This takes quite a long time to run and slows down my script execution time considerably. Could anyone advise of a better(faster) way to accomplish this? I have tried doing this all in one go, using IF(Prod = A, SUM(AMOUNT)) as SUM_A, IF(PROD = B, SUM(AMOUNT) as SUM_B but these creates duplicate rows in the results table (but is much much faster)&lt;/P&gt;&lt;P&gt;Using the example data attached - the result should be:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CLIENT_KEY&lt;/TD&gt;&lt;TD&gt;PROD A&lt;/TD&gt;&lt;TD&gt;PROD B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CLIENT 1&lt;/TD&gt;&lt;TD&gt;&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;&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;&amp;nbsp; 473&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 360&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I try to do all in one table I get a result something like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CLIENT_KEY&lt;/TD&gt;&lt;TD&gt;PROD A&lt;/TD&gt;&lt;TD&gt;PROD B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CLIENT 1&lt;/TD&gt;&lt;TD&gt;&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;&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;&amp;nbsp; 473&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CLIENT 1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;360&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I presume the group by is causing it not to combine into the same row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any guidance on this, im sure there is a simple answer I am missing!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 01:24:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670209#M449406</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2024-11-16T01:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670231#M449408</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/54672"&gt;@ben2r&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Left join performance issues are fairly common and there's a few ways around them. The first thing I like to consider is "do I really need to join these tables". The Qlik engine is really optimised to work in a different way, if in creating your mini sum tables it sounds like you'll have associations available to you on client_key, you could just leave them be. There's a whole lot of data modelling religious arguments that might be started with what I've just said but I think it's worth thinking about, there's plenty of evidence in articles here on community that it will perform well and meet your needs.&lt;/P&gt;&lt;P&gt;Leaving the above aside, there are various options discussed here on community if you search on "left join performance" (I prefer to just search in Google prefixing my search with "Qlik"). I'd take a look at the Keep (there is a left keep) function and mapping load, either of which might meet your needs. There's a telling line in the help for the Keep statement: "&lt;SPAN&gt;Explicit joins should therefore generally be avoided in&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="CommonComponentsQlik Sense"&gt;Qlik Sense&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;scripts".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm not suggesting an explicit solution here as everyone's data and environment is different and you might need to test a few things for yourself to see what your performance is like. I also don't know how fixed you are on having to have everything in the one table.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rod&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 22:00:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670231#M449408</guid>
      <dc:creator>Rodj</dc:creator>
      <dc:date>2020-01-28T22:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670253#M449414</link>
      <description>&lt;P&gt;What's in your Group By? It shouldn't create duplicates if you just have %CLIENT_KEY.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 00:27:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670253#M449414</guid>
      <dc:creator>MikeW</dc:creator>
      <dc:date>2020-01-29T00:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670258#M449416</link>
      <description>&lt;P&gt;It isn't creating duplicates, each source record only has a single value in %PROD_LINE which can be "PROD_A" or "PROD_B". conceptually what needs to happen is a de-pivoting of the data, i.e. pivot %PROD_LINE into PROD_A and PROD_B columns.&lt;/P&gt;&lt;P&gt;There's a number of ways this can be dealt with as I alluded to above, but if we need to create separate sum_a and sum_b columns they will probably need to be created separately. That said we don't have any information on the grain of the original fact table etc. My approach would be to simply create separate result tables, e.g.:&lt;/P&gt;&lt;P&gt;Sum_A:&lt;/P&gt;&lt;P&gt;Load&amp;nbsp;&lt;/P&gt;&lt;P&gt;%CLIENT_KEY&lt;/P&gt;&lt;P&gt;Sum(AMOUNT) as Sum_A&lt;/P&gt;&lt;P&gt;resident&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;FACT_CROSS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;group by&amp;nbsp;%CLIENT_KEY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They don't need to be joined back to the fact, it is probably unnecessary work as the QIX engine will handle the simple association easily and without any of the potential complications that would arise in a SQL based world. Using Keep or a mapping load would then combine the tables either logically or physically if desired.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 01:01:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670258#M449416</guid>
      <dc:creator>Rodj</dc:creator>
      <dc:date>2020-01-29T01:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670265#M449417</link>
      <description>Hi I would suggest to not use Sum Group in Qlik Script Part given the high volume data you have. I once had similar situation and it caused long time to execute the scripts. What I do is to not use sum in back end, instead, use it in front when you code chart. Thanks!</description>
      <pubDate>Wed, 29 Jan 2020 02:41:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670265#M449417</guid>
      <dc:creator>alex00321</dc:creator>
      <dc:date>2020-01-29T02:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670266#M449418</link>
      <description>&lt;P&gt;That's a good call too. Pre-calculating isn't often of real benefit. The volumes being talked about here still aren't very big unless you are just developing on desktop.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 02:44:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670266#M449418</guid>
      <dc:creator>Rodj</dc:creator>
      <dc:date>2020-01-29T02:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670269#M449419</link>
      <description>True</description>
      <pubDate>Wed, 29 Jan 2020 02:49:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670269#M449419</guid>
      <dc:creator>alex00321</dc:creator>
      <dc:date>2020-01-29T02:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670293#M449421</link>
      <description>&lt;P&gt;It might be caused by the If being outside the sum rather than inside the sum.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have a high aggregation rate from this sum (ie from 15m records to 10k records after the sum) then the fastest way is to do the ifs inside the sums and sort by the group by key first. This part is multi threaded. Then do a sum group by on the sorted table using resident load. Group by is single threaded for some weird reason and can be helped by fronting the work (ie any calculations inside sums, sorting, where filtering, combining many group by fields in a single key) when it is multi threaded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For only 15m records, you might be better off doing the sum using set analysis on the front end, which is essentially a multi threaded group by. If you are using the sum in nested aggrs and reused many times in a noncacheable way, then precalculation might make more sense. Definitely try and see if the precalculation actually improves anything. There are lots of options for optimization on the front end as well.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 06:02:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670293#M449421</guid>
      <dc:creator>MikeW</dc:creator>
      <dc:date>2020-01-29T06:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670345#M449426</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/88402"&gt;@Rodj&lt;/a&gt;&amp;nbsp; thanks for your thoughts on this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is part of a broader project to build a simple data model from many different sources and I was trying to keep things in a simple star schema kind of approach (in the past we have created monster snowflake DMs which seem to be terrible on dashboard performance).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like the idea of the mapping load - I will give that a try.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Running separate tables has not made a massive difference - still adds 5 mins onto a script otherwise loading in ~45 seconds&lt;/P&gt;&lt;P&gt;Elsewhere there was a question about granularity. The file I sent was slightly abridged, the main table of 14m rows ish contains a row for each month for the last 24 months and within each month multiple products per client and value traded for each client. The unique list of clients from this 14m is about 60k.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 09:27:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670345#M449426</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2020-01-29T09:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script Sum If With Groups Causes Duplication</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670365#M449428</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/86964"&gt;@MikeW&lt;/a&gt;&amp;nbsp; thanks for the input. I was not aware of that on the ifs. I have updated in my load script and it reduced the load time slightly.&lt;/P&gt;&lt;P&gt;Front end certainly works but in the past we have seen quite slow dashboard speeds when clicking through different cuts of the data. I am not certain how much of this was due to a badly designed DM (uber snowflake as mentioned above).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your multi-step suggestion works a treat here - second pass brings all on one result per client rel and keeps my data model looking nice and clean!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 10:24:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Sum-If-With-Groups-Causes-Duplication/m-p/1670365#M449428</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2020-01-29T10:24:53Z</dc:date>
    </item>
  </channel>
</rss>

