<?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: Optimizing sums with fields from two tables in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845835#M470351</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with everything Rob and Oleg have said - this is not easy...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Most cases like this - also the example with Sum( NoOfUnits * UnitCost ) - are &lt;EM&gt;many-to-one relationships&lt;/EM&gt;. Then the obvious answer is: Make a copy of UnitCost in the fact table. Then the above aggregation is fast. Your example with OrderLines is such a relationship: &lt;EM style="text-decoration: underline;"&gt;Each order line only has one cost.&lt;/EM&gt; Then do what Oleg suggests: calculate the total cost in the OrderLines table, already in the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you have a true many-to-many relationship, I don't have a good answer. Your suggestion with Aggr() may be a good one, although my experience of Aggr() is that it is CPU-expensive...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jun 2015 20:47:18 GMT</pubDate>
    <dc:creator>hic</dc:creator>
    <dc:date>2015-06-08T20:47:18Z</dc:date>
    <item>
      <title>Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845831#M470347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;Greetings everyone,&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;I am looking for ways to optimize a sum expression that uses fields from two tables.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;SPAN lang="en-US"&gt;As an example, take the expression &lt;/SPAN&gt;&lt;SPAN lang="sv"&gt;Sum( NoOfUnits * UnitCost ), where NoOfUnits is in one fact table, and UnitCost is in another. As explained in this article, &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A _jive_internal="true" href="https://community.qlik.com/blogs/qlikviewdesignblog/2013/08/20/the-calculation-engine"&gt;https://community.qlik.com/blogs/qlikviewdesignblog/2013/08/20/the-calculation-engine&lt;/A&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;QlikView will generate all applicable combinations of the field values before summing them. &lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;The problem in my case is that both tables can be very large, even though the field that links them such as ProductID, does not have that many distinct values. Generating all combinations will result in a very large amount of combinations to summarize.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;Take for example this scenario: The first fact table contains order lines, with a number of dimensions such as product ID, customer ID, sales channel, and the number of units sold for that order line. The number of order lines can be many millions, even though the number of distinct products is only a few hundred.&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;The second fact table contains the unit cost for each product, broken down into many components that form the product, and other dimensions such as component supplier.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;It would be possible to combine these tables in the load script, but that would create one extremely large fact table, with many billions of rows. The idea with two fact tables is that these represent a more normalized view of the data. In the example, the breakdown of product cost onto components is the same regardless of which customer buys that specific product, but it will be different for different products.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;An example of a simple analysis is that the user selects a set of order lines, for example by choosing a customer, a customer group, or a sales channel. Based on the selected order lines, we want to display the component cost per component.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;Both intuitively and mathematically, it should yield the same result, but in a more efficient way, if we first summarize NoOfUnits per product for the selected order lines, and then combine that with the fact table that contains unit cost per product and other dimensions, instead of taking each separate order line and combine with the fact table with unit cost. This has to be done after the selection has been made, since we would like the user to have full flexibility in how they choose the order lines.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;SPAN lang="en-US"&gt;For the most simple analysis, which just shows the total amount per product for the selection, it seems to work well to replace the slower &lt;/SPAN&gt;&lt;SPAN lang="sv"&gt;Sum( NoOfUnits * UnitCost ) with the following expression: &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Sum (aggr(sum(NoOfUnits)*sum(UnitCost), Product))&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;It summarizes the number of units per product and the unit cost &lt;STRONG&gt;per product&lt;/STRONG&gt;, and then multiplies them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;However, I have been unable to create an expression that always works if I want to include dimensions from one or both of the fact tables in the analysis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;I'll try to attach a sample document that uses randomly generated data that can be used to show the problem. On my machine, when selecting one product group, it takes a few seconds to load the "Amount per product slow" analysis, while "Amount per product fast", which uses the more complicated expression with aggr above, loads more or less instantly. Below that is an "Amount per component" which I have not been able to get faster. The load script can easily be changed to see the effects of larger or smaller number of rows in the tables.&lt;/P&gt;&lt;P lang="en-US"&gt;&lt;/P&gt;&lt;P lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"&gt;Here are some workarounds that I already know of, if it simply is not possible to create a more efficient expression:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Creating several documents for different kinds of analyses, where the fact tables are summarized to only contain the dimensions necessary for that particular analysis. For example, one analysis where the user must select a customer group. We can summarize the order lines per product and customer group, which will reduce the amount of data. This limits the flexibility of the user though.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Increase the computation resources (more/faster CPU cores, more memory, adjusting working set settings and so on). The computations are not performed more efficiently, but they can be done faster with more expensive hardware.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Pre-cache common selections after reloading the document.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Thanks in advance for any suggestions you may have,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri; font-size: 11.0pt;"&gt;Robert&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 13:15:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845831#M470347</guid>
      <dc:creator />
      <dc:date>2015-05-25T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845832#M470348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another way to try to describe what I would like to accomplish:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The user filters a big number of order lines by selecting from one or more dimensions, such as product group or customer group. QlikView is great at this.&lt;/LI&gt;&lt;LI&gt;A chart displays the total number of units per product, for the selected order lines. Even though there may be a lot of order lines, this chart will only have a few hundred rows or so. This is easy to implement and works fine.&lt;/LI&gt;&lt;LI&gt;I would like to add more charts that take the products and the total number of units for the selection, and combine this with a second fact table to break this down into costs per some dimensions in that second fact table. Ideally this would be in the same document, but if it would be possible to navigate to a second document and pass information about the selected products and the number of units for each, that would also work.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm happy to clarify anything in this question, just ask.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 09:43:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845832#M470348</guid>
      <dc:creator />
      <dc:date>2015-06-03T09:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845833#M470349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your problem is one of the toughest ones, because there is no easy "book answer" to prescribe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a known fact, and you mentioned it, that QlikView doesn't perform well when two operands within the same aggregation are coming from different tables:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sum(Field1*Field2).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, because of the many-to-many relationship between the two tables, it's not trivial to bring the two fields together.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your suggested solution with AGGR() is perhaps the best "proxy" for a better performance. I'd like to understand your comment where you mentioned that you weren't able to formulate a more advanced analysis involving other dimensions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other than that, I'd suggest to look for compromises and "work around" solutions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- If total cost is used in many calculations (charts), I'd suggest to pre-calculate the total cost field in the fact table.&lt;/P&gt;&lt;P&gt;- If cost components can be summarized into a few commonly used buckets (for example, the famous Material, Labor, and Overhead), I'd also suggest pre-calculating these three fields in the fact table.&lt;/P&gt;&lt;P&gt;- Hopefully, these work around solutions can cover a large part of your needs. For truly dynamic calculations that allow selecting any combinations of cost components and can't be pre-calculated, you'd have to take the user to the "slow" sheet with a warning that this calculation may take longer than usual. Even here, I'd suggest finding a way of using your AGGR() solution at the appropriate level of detail. Just watch for the number of distinct values that you need to generate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;A href="http://masterssummit.com/"&gt;Masters Summit for QlikView&lt;/A&gt; - take your QlikView skills to the next level!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 18:50:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845833#M470349</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-08T18:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845834#M470350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is a challenging one. I think you are stuck in "workaround" land, pre-calc as much as possible etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One modeling thing you can do is make sure all your DImension tables (including the ComponentFacts table) are DISTINCT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 19:46:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845834#M470350</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2015-06-08T19:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845835#M470351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with everything Rob and Oleg have said - this is not easy...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Most cases like this - also the example with Sum( NoOfUnits * UnitCost ) - are &lt;EM&gt;many-to-one relationships&lt;/EM&gt;. Then the obvious answer is: Make a copy of UnitCost in the fact table. Then the above aggregation is fast. Your example with OrderLines is such a relationship: &lt;EM style="text-decoration: underline;"&gt;Each order line only has one cost.&lt;/EM&gt; Then do what Oleg suggests: calculate the total cost in the OrderLines table, already in the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you have a true many-to-many relationship, I don't have a good answer. Your suggestion with Aggr() may be a good one, although my experience of Aggr() is that it is CPU-expensive...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 20:47:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845835#M470351</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2015-06-08T20:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845836#M470352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Thanks a lot for your quick answers! I'll make a note of the additional compromises/work arounds that have been suggested. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;I had already tried various aggr expressions, but I gave it another go today after your replies, and this expression actually seems to work faster while giving the same result, for a simple chart that uses the component dimension from the other fact table with unit cost:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;&lt;STRONG&gt;Sum (aggr( NODISTINCT sum(NoOfUnits), Product)*aggr( sum(UnitCost), Product, Component))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;I don't really understand why NODISTINCT makes a difference, but without it, the result is usually completely wrong. Conceptually this kind of calculation is what I had in mind - summarize the tables on only the dimensions necessary for linking them and for the chart dimensions before the multiplication, but until now didn't manage to get working. Do you think this kind of expression makes sense? It feels a little bit scary to have different dimensions in the two aggr parts, even though that is what theoretically is necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Here are some of the other aggr expressions I've been trying: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Sum (aggr( sum(NoOfUnits), Product)*aggr( sum(UnitCost), Product, Component))&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Fast, but gives completely wrong result. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Sum (aggr(sum(NoOfUnits)*sum(UnitCost), Product, Component))&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Sum (aggr(sum(NoOfUnits)*sum(UnitCost), Component, Product))&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Seems to give the same result but is not faster than the original simple expression. I assume that it still needs to generate the combinations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Sum (aggr( sum(NoOfUnits), Product, Component)*aggr( sum(UnitCost), Product, Component))&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;Seems to give the same result but is slower than the original simple expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Calibri; font-size: 11.0pt;"&gt;It should be noted that I tried to extend the working expression to include one more dimensions from the table with NoOfUnits, but that gave incorrect results so far.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 09:56:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845836#M470352</guid>
      <dc:creator />
      <dc:date>2015-06-09T09:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845837#M470353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe the NODISTINCT is needed because you have the mixed granularity between your two AGGR-generated "cubes." That is, you have one row per Product &amp;amp; Component for UnitCost; but only one row per Product&amp;nbsp; for the NoOfUnits. The NODISTINCT is telling the engine to take NoOfUnits results and propagating them across every row of the more granular UnitCost "cube."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've had a few challenges like your situation and I've typically used ONLY() as my inner aggregation function for the cost. Knowing that the aggr() is taking me down to the lowest level of granularity in my item master, then there could only be one value for that cost.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've never tested the performance impact of the only() vs. a sum() ... perhaps Oleg or Henric could comment on that. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Bill&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 15:57:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845837#M470353</guid>
      <dc:creator>bill_lay_vc</dc:creator>
      <dc:date>2015-06-09T15:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845838#M470354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are on the right path, but the actual formulas that you listed seems to be incorrect. Here are some thoughts and some suggestions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I don't think you need to include Component into your AGGR dimensions, unless your chart has Component as a chart dimension. In all other cases, Component doesn't need to be there. If users select certain components, the available (associated) components will get aggregated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- In your aggr(), you definitely need to list Product and all chart dimensions for each chart. For example, in a chart by Customer, you should include Customer as the dimension of the AGGR().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I picture something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sum(AGGR( sum(&lt;SPAN style="color: #3d3d3d; font-family: Calibri; font-size: 14.6666669845581px;"&gt;NoOfUnits) * sum(&lt;SPAN style="color: #3d3d3d; font-family: Calibri; font-size: 14.6666669845581px;"&gt;UnitCost), Product, ChartDim1, ChartDim2, ChartDim3, ...))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, this approach may or may not resolve the issue of building the possible combinations, but logically it should be correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.amazon.com/QlikView-Your-Business-expert-Discovery/dp/1118949552/ref=sr_1_1?ie=UTF8&amp;amp;qid=1433867626&amp;amp;sr=8-1&amp;amp;keywords=qlikview+your+business"&gt;QlikView Your Business&lt;/A&gt; - check out my new book, coming out in August!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 16:34:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845838#M470354</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-09T16:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845839#M470355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to post a correction about NODISTINCT - that was a dumb moment... AGGR() is distinct by default.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:44:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845839#M470355</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-09T17:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845840#M470356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did some testing on a somewhat similar data structure, and I have mixed results...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In one specific instance, I managed to gain a huge improvement in performance (from 15 sec down to 1.2 sec) when I used the AGGR() function, similar to the one that I suggested, with a single dimension that was close to your Product Dimension:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;sum(AGGR( sum(&lt;/SPAN&gt;&lt;SPAN style="font-size: 14.6666669845581px; font-family: Calibri; color: #3d3d3d;"&gt;NoOfUnits) * sum(&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 14.6666669845581px;"&gt;UnitCost), Product))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 14.6666669845581px; font-style: inherit; font-family: Calibri; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 14.6666669845581px; font-style: inherit; font-family: Calibri; font-weight: inherit;"&gt;However, as soon as I added another dimension, the AGGR() solution performed much worse than the original. The original formula showed a marginal increase in calculation time (19 sec.) while the AGGR() solution showed much worse results (82 sec. and worse).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 14.6666669845581px; font-style: inherit; font-family: Calibri; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 14.6666669845581px; font-style: inherit; font-family: Calibri; font-weight: inherit;"&gt;Conclusion: You might have limited opportunities to improve performance with AGGR(), but only in some limited scenarios. Other than that, unless others offer some clever ideas, I'd revert to work-around solutions...&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2015 18:36:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845840#M470356</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-09T18:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845841#M470357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That makes sense, thanks for the explanation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 14:33:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845841#M470357</guid>
      <dc:creator />
      <dc:date>2015-06-10T14:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845842#M470358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for all your efforts, Oleg!&lt;/P&gt;&lt;P style="font-size: 11pt; font-family: Calibri; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 11pt; font-family: Calibri; color: #3d3d3d;"&gt;In a simple chart that only uses component as dimension, it did seem to work to use the expression I posted earlier. In that case, the dimensions from the order line fact table are not displayed in the chart, but used to filter the order lines in various ways. The chart then breaks down the selected order lines on the components that have been used by all products sold on those order lines. In the real application I have in mind, this kind of analysis makes sense.&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 11pt; font-family: Calibri; color: #3d3d3d;"&gt;&lt;STRONG style="font-style: inherit; font-size: 14.6666669845581px; font-family: inherit;"&gt;Sum (aggr( NODISTINCT sum(NoOfUnits), Product)*aggr( sum(UnitCost), Product, Component))&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 11pt; font-family: Calibri; color: #3d3d3d;"&gt;&lt;STRONG style="font-style: inherit; font-size: 14.6666669845581px; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-size: 11pt; font-family: Calibri; color: #3d3d3d;"&gt;I agree with your conclusion that these kind of expressions probably only work in limited scenarios. For some other scenarios where charts and selections only need fields from the order lines fact tables, it makes sense to add the total cost to the order lines fact table as you and Henric suggested. I think this is enough for the problem I need to solve now, even though it is always nice to know solutions that are as generic as possible.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 14:55:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845842#M470358</guid>
      <dc:creator />
      <dc:date>2015-06-10T14:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845843#M470359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I came exactly to the same conclusions. I'm curious - for your chart by Component, would it be faster or slower to calculate the same using this formula:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-style: inherit; font-size: 14.6666669845581px; font-family: inherit; color: #3d3d3d; background-color: #f2f2f2;"&gt;Sum (aggr( sum(NoOfUnits) *&amp;nbsp; sum(UnitCost), Product, Component))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-style: inherit; font-size: 14.6666669845581px; font-family: inherit; color: #3d3d3d; background-color: #f2f2f2;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Could you please compare the two formulas and post the result?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oleg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 15:41:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845843#M470359</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-10T15:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845844#M470360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Oleg,&lt;/P&gt;&lt;P&gt;here are some test results for that chart. I did try both a stopwatch and checking the CalcTime on the sheet properties.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Unoptimized expression &lt;/SPAN&gt;sum(NoOfUnits*UnitCost)&lt;BR /&gt;12 seconds / 11390 CalcTime&lt;/LI&gt;&lt;LI&gt;Sum (aggr( NODISTINCT sum(NoOfUnits), Product)*aggr( sum(UnitCost), Product, Component))&lt;BR /&gt;&amp;lt; 0.5 seconds / 109 CalcTime&lt;/LI&gt;&lt;LI&gt;Sum (aggr( sum(NoOfUnits) *&amp;nbsp; sum(UnitCost), Product, Component))&lt;BR /&gt;20 seconds / 19594 CalcTime&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As far as I can see, all formulas produce the same result for the test data. In my test, the formula you suggested is slower.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 16:29:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845844#M470360</guid>
      <dc:creator />
      <dc:date>2015-06-10T16:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845845#M470361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is so interesting! Thanks for sharing!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Jun 2015 19:27:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845845#M470361</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-06-10T19:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing sums with fields from two tables</title>
      <link>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845846#M470362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After some more experimentation, I discovered that the following expression also seems to work well in charts that only display dimensions related to the second fact table. Having one less AGGR might be good for performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum (aggr( NODISTINCT sum(NoOfUnits), Product) * UnitCost)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;Essentially this performs what I tried to explain in the original post, but did not know how to create an expression for.&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P lang="en-US" style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN style="font-family: Calibri; font-size: 11pt; line-height: 1.5em;"&gt;Both intuitively and mathematically, it should yield the same result, but in a more efficient way, if we first summarize NoOfUnits per product for the selected order lines, and then combine that with the fact table that contains unit cost per product and other dimensions, instead of taking each separate order line and combine with the fact table with unit cost. This has to be done after the selection has been made, since we would like the user to have full flexibility in how they choose the order lines.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The limitation here is that the chart can only have dimensions from one of the fact tables, but it will use the selection in the other fact table to calculate the result, which is what I mainly needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know it is difficult to understand the problem, but the performance difference is huge compared to joining the two fact tables when loading and producing a multi billion row fact table, or having QlikView produce all those combinations when creating a chart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll mark this question as answered, since this solves the problem as I stated it. However, if anyone has further input now or in the future, feel free to add comments.&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Thanks to everyone that contributed to the discussion!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 13:58:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimizing-sums-with-fields-from-two-tables/m-p/845846#M470362</guid>
      <dc:creator />
      <dc:date>2015-06-24T13:58:36Z</dc:date>
    </item>
  </channel>
</rss>

