<?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 Transfer calculation from frontend to load script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Transfer-calculation-from-frontend-to-load-script/m-p/1979403#M80847</link>
    <description>&lt;P&gt;Sorry if this seems so basic, but I'm developing a vehicle utilization dashboard and was able to calculate "non usage" in the frontend, but once I have more than a month's worth of data loaded, it makes the dashboard &lt;U&gt;very&lt;/U&gt; slow. Ultimately I would like to convert this to work in the load script (as a 1,0 or Y,N flag?! ) and I can simply count / sum that in the frontend.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main data source only has entries if a vehicle was used. In order to find non-usage, I had to create a table by cartesian joining all valid vehicle numbers with valid dates and then I LEFT JOIN in the usage data. So if a vehicle was used M,W, I would get a 4 for "non-usage" (T,Th,F,S....Sun is a non-valid day).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My set analysis is aggregating by date and vehicle&amp;nbsp; as that is how I am rolling up the data. "In_Shop" is a flag I create in the SQL pull (CASE WHEN statement) b/c if a vehicle was designated as "in the shop for repairs", then I don't want that to count against a facility for the vehicle not being utilized.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the formula I'm hoping to convert:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Count(AGGR(IF(SUM(Utilization)=0,vehicle),vehicle,Date)) - Count({&amp;lt;In_Shop={"YES"}&amp;gt;}Date)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I tried a simple IF((endmileage-beginmileage)=0,1,0) and that works, but &lt;U&gt;ONLY&lt;/U&gt; for those vehicles where end-begin = 0 (super rare). For vehicles with no entries, I don't get a count and this is a major issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not going to bother with including the SQL pulls, but here is my QLIK script for the cartesian and left join if it helps at all....&lt;/P&gt;
&lt;P&gt;NoConcatenate&lt;BR /&gt;[DATA]:&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;RESIDENT [xVEHICLES];&lt;BR /&gt;JOIN&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;RESIDENT [xDATES];&lt;BR /&gt;DROP TABLE [xVEHICLES];&lt;BR /&gt;DROP TABLE [xDATES];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LEFT JOIN&lt;/P&gt;
&lt;P&gt;LOAD&lt;BR /&gt;financenumber as utilized_finance,&lt;BR /&gt;routetypecode as Route_Type,&lt;BR /&gt;beginodometer as Begin_Mileage,&lt;BR /&gt;endodometer as End_Mileage,&lt;BR /&gt;eventenddate as Date,&lt;BR /&gt;eventstarttime as Start_Time,&lt;BR /&gt;eventendtime as End_Time,&lt;BR /&gt;vehiclenumber as vehicle,&lt;BR /&gt;endodometer - beginodometer as Utilization,&lt;BR /&gt;in_shop as In_Shop,&lt;/P&gt;
&lt;P&gt;Resident xAVUS;&lt;BR /&gt;Drop Table xAVUS;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Sep 2022 20:42:51 GMT</pubDate>
    <dc:creator>drew61199</dc:creator>
    <dc:date>2022-09-09T20:42:51Z</dc:date>
    <item>
      <title>Transfer calculation from frontend to load script</title>
      <link>https://community.qlik.com/t5/App-Development/Transfer-calculation-from-frontend-to-load-script/m-p/1979403#M80847</link>
      <description>&lt;P&gt;Sorry if this seems so basic, but I'm developing a vehicle utilization dashboard and was able to calculate "non usage" in the frontend, but once I have more than a month's worth of data loaded, it makes the dashboard &lt;U&gt;very&lt;/U&gt; slow. Ultimately I would like to convert this to work in the load script (as a 1,0 or Y,N flag?! ) and I can simply count / sum that in the frontend.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main data source only has entries if a vehicle was used. In order to find non-usage, I had to create a table by cartesian joining all valid vehicle numbers with valid dates and then I LEFT JOIN in the usage data. So if a vehicle was used M,W, I would get a 4 for "non-usage" (T,Th,F,S....Sun is a non-valid day).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My set analysis is aggregating by date and vehicle&amp;nbsp; as that is how I am rolling up the data. "In_Shop" is a flag I create in the SQL pull (CASE WHEN statement) b/c if a vehicle was designated as "in the shop for repairs", then I don't want that to count against a facility for the vehicle not being utilized.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the formula I'm hoping to convert:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Count(AGGR(IF(SUM(Utilization)=0,vehicle),vehicle,Date)) - Count({&amp;lt;In_Shop={"YES"}&amp;gt;}Date)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I tried a simple IF((endmileage-beginmileage)=0,1,0) and that works, but &lt;U&gt;ONLY&lt;/U&gt; for those vehicles where end-begin = 0 (super rare). For vehicles with no entries, I don't get a count and this is a major issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not going to bother with including the SQL pulls, but here is my QLIK script for the cartesian and left join if it helps at all....&lt;/P&gt;
&lt;P&gt;NoConcatenate&lt;BR /&gt;[DATA]:&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;RESIDENT [xVEHICLES];&lt;BR /&gt;JOIN&lt;BR /&gt;Load&lt;BR /&gt;*&lt;BR /&gt;RESIDENT [xDATES];&lt;BR /&gt;DROP TABLE [xVEHICLES];&lt;BR /&gt;DROP TABLE [xDATES];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LEFT JOIN&lt;/P&gt;
&lt;P&gt;LOAD&lt;BR /&gt;financenumber as utilized_finance,&lt;BR /&gt;routetypecode as Route_Type,&lt;BR /&gt;beginodometer as Begin_Mileage,&lt;BR /&gt;endodometer as End_Mileage,&lt;BR /&gt;eventenddate as Date,&lt;BR /&gt;eventstarttime as Start_Time,&lt;BR /&gt;eventendtime as End_Time,&lt;BR /&gt;vehiclenumber as vehicle,&lt;BR /&gt;endodometer - beginodometer as Utilization,&lt;BR /&gt;in_shop as In_Shop,&lt;/P&gt;
&lt;P&gt;Resident xAVUS;&lt;BR /&gt;Drop Table xAVUS;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 20:42:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Transfer-calculation-from-frontend-to-load-script/m-p/1979403#M80847</guid>
      <dc:creator>drew61199</dc:creator>
      <dc:date>2022-09-09T20:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Transfer calculation from frontend to load script</title>
      <link>https://community.qlik.com/t5/App-Development/Transfer-calculation-from-frontend-to-load-script/m-p/1979854#M80869</link>
      <description>&lt;P&gt;I would use a bit different approach which concatenates the missing data to the existing ones, for example with something like:&lt;/P&gt;
&lt;P&gt;t1: load date from Calendar; join(t1) load vehicles from Vehicles; // creates the cartesian&lt;/P&gt;
&lt;P&gt;t2: load *, date &amp;amp; '|' &amp;amp; vehicle as ExistsKey, 'Facts' as Source fromFactData;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;concatenate(t2)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;load&amp;nbsp;date, vehicle, 0 as Mileage, 'none' as xyz, ..., 'Populated' as Source&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from t1 where not exists(ExistsKey,&amp;nbsp;date &amp;amp; '|' &amp;amp; vehicle);&lt;/P&gt;
&lt;P&gt;Benefits would be that you could give all missing records a real value by setting the fields to 0 or 'none' instead of NULL which would the join return (of course you may add a following load and checking the exists of values and adjusting the values appropriate - but it would be an additionally step) and you could set a Source information to be able to differentiate between the existing and populated ones.&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 13:08:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Transfer-calculation-from-frontend-to-load-script/m-p/1979854#M80869</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-09-12T13:08:18Z</dc:date>
    </item>
  </channel>
</rss>

