<?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 Use expressions with fields from both, Direct Table and In-Mem table in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Use-expressions-with-fields-from-both-Direct-Table-and-In-Mem/m-p/620997#M437811</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;As you know, Direct Discovery operates with an SQL-based table. The "Direct Table" logic, that QlikView has since QV11.2 SR5, is aware of so-called DIMENSION fields, MEASURE fields and DETAIL fields (to be defined as such in the Load Script). &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;If QlikView finds inside of an expression a &lt;STRONG&gt;Measure field&lt;/STRONG&gt;, it will look for the surrounding aggregation formula (SUM, AVG, MIN, MAX) and query that string (including the aggregation formula) to the SQL connection. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Assume that we have this structure. The DirectTable has one Measure Field (_Umsatz), which is not shown in the Table-Model Viewer, so I painted it there manually.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;IMG __jive_id="56936" alt="ddd.png" class="jive-image jiveImage" src="https://community.qlik.com/legacyfs/online/56936_ddd.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;If your expression is like:&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;SUM(_Umsatz)*0.8816&lt;/STRONG&gt;&amp;nbsp; then SUM(_Umsatz) will be queried from SQL and the result will be multiplied with 0.8816 in QlikView. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;In more detail: &lt;STRONG&gt;SUM(_Umsatz)&lt;/STRONG&gt; will be in the middle of a SELECT statement, which also has a GROUP BY according to the current dimensionality context of the chart. There is likely also a WHERE clause if "_%Bestell-Nr" and "_%Artikel-NR" have any associated selection from any of the linked tables. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Now, assume you want to sum a datarow-wise multiplication of _Umsatz with another field from a linked in-memory table. If there was no Direct Table but a In-Memory-only data model, the formula would look like&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: 'Calibri','sans-serif';"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;STRONG&gt;SUM(_Umsatz * _Artikel.Einzelpreis)&lt;/STRONG&gt;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;... this won't work in Direct Discovery.&lt;/SPAN&gt; Why?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Because QlikView slices the expression into as many queries as it finds aggregation formulas and "roots" each part either to SQL or to the In-Memory Engine. The rule is, if &lt;SPAN style="text-decoration: underline;"&gt;one&lt;/SPAN&gt; Direct Table Measure Field is involved in one aggregation formula, that entire aggregation formula is going to be sent to SQL. And it will fail here, since "_Artikel.Einzelpreis" is not a field in the DirectTable and unknown to SQL. QlikView can not mix &lt;SPAN style="text-decoration: underline;"&gt;two&lt;/SPAN&gt; types of fields, In-Memory and SQL fields &lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;inside &lt;SPAN style="text-decoration: underline;"&gt;one&lt;/SPAN&gt; Aggregation formula!&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;There is a way to solve this using &lt;STRONG&gt;Aggr()&lt;/STRONG&gt; to create the dimensionality between the two linked tables (Direct Table and In-Memory) and then get the results:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;Sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;Aggr&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;Sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: gray; font-size: 9.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;&lt;EM&gt;_&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;Umsatz) * &lt;/SPAN&gt;&lt;SPAN style="color: gray; font-size: 9.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;&lt;EM&gt;_&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;Artikel.Einzelpreis, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: maroon;"&gt;[&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: maroon;"&gt;_%Artikel-Nr]))&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 9.0pt; font-family: 'Courier New';"&gt;// don't judge this formula whether it makes business sense or not, it's just for illustration!&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above example&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Aggr forms a temporary "hyper-cube" over the dimensionalty of "_%Artikel_Nr" which is the granularity of the linked table where my In-Memory field sits ("_%Artikel_Nr" is the primary key of the "Artikel" table).&lt;/LI&gt;&lt;LI&gt;The Aggregation formula "Sum(_Umsatz)" is sent to, and successfully replied from, the SQL connection, grouped by "_%Artikel-Nr"&lt;/LI&gt;&lt;LI&gt;Then the result-matrix, which has a compatible dimensionality now,&amp;nbsp; is multiplied with the *_Artikel.Einzelpreis".&lt;/LI&gt;&lt;LI&gt;The outer Sum() is required if you use this formula in any other dimensionality than "Arikel" (example if this is in a chart where the dimensions is "_Kategorie.Kategoriename")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't use this too extensively, as the Aggr() enforces the Direct Discovery to make an addtional Query to SQL before it can continue with the calculation. This will have an effect on the performance of the chart generation.&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Look into the options of "flattening" (joining) that desired field from the In-Memory table into the SQL table if possible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Enjoy Direct Discovery&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Apr 2014 20:30:21 GMT</pubDate>
    <dc:creator>ChristofSchwarz</dc:creator>
    <dc:date>2014-04-09T20:30:21Z</dc:date>
    <item>
      <title>Use expressions with fields from both, Direct Table and In-Mem table</title>
      <link>https://community.qlik.com/t5/QlikView/Use-expressions-with-fields-from-both-Direct-Table-and-In-Mem/m-p/620997#M437811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;As you know, Direct Discovery operates with an SQL-based table. The "Direct Table" logic, that QlikView has since QV11.2 SR5, is aware of so-called DIMENSION fields, MEASURE fields and DETAIL fields (to be defined as such in the Load Script). &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;If QlikView finds inside of an expression a &lt;STRONG&gt;Measure field&lt;/STRONG&gt;, it will look for the surrounding aggregation formula (SUM, AVG, MIN, MAX) and query that string (including the aggregation formula) to the SQL connection. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Assume that we have this structure. The DirectTable has one Measure Field (_Umsatz), which is not shown in the Table-Model Viewer, so I painted it there manually.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;IMG __jive_id="56936" alt="ddd.png" class="jive-image jiveImage" src="https://community.qlik.com/legacyfs/online/56936_ddd.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;If your expression is like:&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;SUM(_Umsatz)*0.8816&lt;/STRONG&gt;&amp;nbsp; then SUM(_Umsatz) will be queried from SQL and the result will be multiplied with 0.8816 in QlikView. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;In more detail: &lt;STRONG&gt;SUM(_Umsatz)&lt;/STRONG&gt; will be in the middle of a SELECT statement, which also has a GROUP BY according to the current dimensionality context of the chart. There is likely also a WHERE clause if "_%Bestell-Nr" and "_%Artikel-NR" have any associated selection from any of the linked tables. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Now, assume you want to sum a datarow-wise multiplication of _Umsatz with another field from a linked in-memory table. If there was no Direct Table but a In-Memory-only data model, the formula would look like&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: 'Calibri','sans-serif';"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;STRONG&gt;SUM(_Umsatz * _Artikel.Einzelpreis)&lt;/STRONG&gt;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;... this won't work in Direct Discovery.&lt;/SPAN&gt; Why?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;Because QlikView slices the expression into as many queries as it finds aggregation formulas and "roots" each part either to SQL or to the In-Memory Engine. The rule is, if &lt;SPAN style="text-decoration: underline;"&gt;one&lt;/SPAN&gt; Direct Table Measure Field is involved in one aggregation formula, that entire aggregation formula is going to be sent to SQL. And it will fail here, since "_Artikel.Einzelpreis" is not a field in the DirectTable and unknown to SQL. QlikView can not mix &lt;SPAN style="text-decoration: underline;"&gt;two&lt;/SPAN&gt; types of fields, In-Memory and SQL fields &lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;inside &lt;SPAN style="text-decoration: underline;"&gt;one&lt;/SPAN&gt; Aggregation formula!&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;There is a way to solve this using &lt;STRONG&gt;Aggr()&lt;/STRONG&gt; to create the dimensionality between the two linked tables (Direct Table and In-Memory) and then get the results:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif'; color: #1f497d;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;Sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;Aggr&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: blue;"&gt;Sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: gray; font-size: 9.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;&lt;EM&gt;_&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;Umsatz) * &lt;/SPAN&gt;&lt;SPAN style="color: gray; font-size: 9.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;&lt;EM&gt;_&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt;Artikel.Einzelpreis, &lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: maroon;"&gt;[&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: maroon;"&gt;_%Artikel-Nr]))&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 9.0pt; font-family: 'Courier New';"&gt;// don't judge this formula whether it makes business sense or not, it's just for illustration!&lt;/SPAN&gt;&lt;SPAN style="font-size: 9.0pt; font-family: 'Courier New'; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above example&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Aggr forms a temporary "hyper-cube" over the dimensionalty of "_%Artikel_Nr" which is the granularity of the linked table where my In-Memory field sits ("_%Artikel_Nr" is the primary key of the "Artikel" table).&lt;/LI&gt;&lt;LI&gt;The Aggregation formula "Sum(_Umsatz)" is sent to, and successfully replied from, the SQL connection, grouped by "_%Artikel-Nr"&lt;/LI&gt;&lt;LI&gt;Then the result-matrix, which has a compatible dimensionality now,&amp;nbsp; is multiplied with the *_Artikel.Einzelpreis".&lt;/LI&gt;&lt;LI&gt;The outer Sum() is required if you use this formula in any other dimensionality than "Arikel" (example if this is in a chart where the dimensions is "_Kategorie.Kategoriename")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't use this too extensively, as the Aggr() enforces the Direct Discovery to make an addtional Query to SQL before it can continue with the calculation. This will have an effect on the performance of the chart generation.&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Look into the options of "flattening" (joining) that desired field from the In-Memory table into the SQL table if possible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Enjoy Direct Discovery&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Apr 2014 20:30:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Use-expressions-with-fields-from-both-Direct-Table-and-In-Mem/m-p/620997#M437811</guid>
      <dc:creator>ChristofSchwarz</dc:creator>
      <dc:date>2014-04-09T20:30:21Z</dc:date>
    </item>
  </channel>
</rss>

