<?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: Optimise Code in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776257#M717837</link>
    <description>&lt;P&gt;The first thing I would do is split the parts with a distinct clause.&lt;/P&gt;&lt;P&gt;Its better to load distinct into a temp table, then do any operations on a second load statement.&lt;/P&gt;&lt;P&gt;Distinct is supposedly a single threaded operation (I've heard people saying contrary to this so I'm not saying it as fact), but I do know a distinct clause will cause all complex operations on the same load statement to run incredibly slowly (e.g. joins, order by, group by, if statements).&lt;/P&gt;&lt;P&gt;Edit: I forgot to mention that the distinct needs to be completely separate load statement, a preceding load doesn't get out the performance hole of the distinct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the Ifs, most appear to be if this is less/greater so probably not much we can do there.&lt;/P&gt;&lt;P&gt;I did spot one - "&lt;SPAN&gt;IF(LEN(FirstRecoverydate)=0,'NA',FirstRecoverydate)&amp;nbsp;&lt;/SPAN&gt;", could this be replaced with an ALT() function?&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2021 11:05:12 GMT</pubDate>
    <dc:creator>MikeA</dc:creator>
    <dc:date>2021-01-21T11:05:12Z</dc:date>
    <item>
      <title>Optimise Code</title>
      <link>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776233#M717836</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;Need to optimise below code. Could you please suggest how I can remove the if condition with same result.&lt;/P&gt;&lt;P&gt;On every left join it increases data load and getting slow process.&lt;/P&gt;&lt;P&gt;CTSUniqueLineMapping:&lt;BR /&gt;LOAD cts_unique_order_line,&lt;BR /&gt;STFA_SoliMaKey,&lt;BR /&gt;STFA_Material,&lt;BR /&gt;STFA_MSLcode,&lt;BR /&gt;STFA_OSLocation,&lt;BR /&gt;STFA_ItemCleaned,&lt;BR /&gt;STFA_OSLastReplanDate,&lt;BR /&gt;STFA_OSMaterialRecoveryDate,&lt;BR /&gt;CalFirstMatRecoveryDate&lt;BR /&gt;FROM&lt;BR /&gt;[C:\HP Environment\Projects\BRD\QVD\BRD6.qvd]&lt;BR /&gt;(qvd);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(CTSUniqueLineMapping)&lt;BR /&gt;LOAD cts_unique_order_line&lt;BR /&gt;, Date(max(CalFirstMatRecoveryDate)) as FirstRecoverydate&lt;BR /&gt;, Date(max(STFA_OSLastReplanDate)) as MaxLastReplanDt&lt;BR /&gt;Resident CTSUniqueLineMapping Group by cts_unique_order_line;&lt;/P&gt;&lt;P&gt;Left Join(CTSUniqueLineMapping)&lt;BR /&gt;LOAD cts_unique_order_line, Date(max(STFA_OSMaterialRecoveryDate)) as LastRecoverydate1&lt;BR /&gt;Resident CTSUniqueLineMapping&lt;BR /&gt;where STFA_OSLastReplanDate=MaxLastReplanDt Group by cts_unique_order_line;&lt;/P&gt;&lt;P&gt;Left Join(CTSUniqueLineMapping)&lt;BR /&gt;LOAD cts_unique_order_line,&lt;BR /&gt;if(IsNull(LastRecoverydate1) and DATE(LastWorkDate(STFA_ItemCleaned, 3))&amp;lt;=STFA_OSLastReplanDate ,Date#('9999-12-31','YYYY-MM-DD'),&lt;BR /&gt;If( DATE(LastWorkDate(STFA_ItemCleaned, 3))&amp;gt;STFA_OSLastReplanDate,'NA',LastRecoverydate1)) AS LastRecoverydate&lt;BR /&gt;Resident CTSUniqueLineMapping;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(CTSUniqueLineMapping)&lt;BR /&gt;LOAD cts_unique_order_line, STFA_Material, STFA_MSLcode, STFA_SoliMaKey, Count(STFA_SoliMaKey) as STFA_SoliMaKey_cnt&lt;BR /&gt;Resident CTSUniqueLineMapping&lt;BR /&gt;Group by cts_unique_order_line, STFA_Material, STFA_MSLcode, STFA_SoliMaKey;&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;BR /&gt;STFA_T1:&lt;BR /&gt;LOAD Distinct cts_unique_order_line,&lt;BR /&gt;STFA_Material,&lt;BR /&gt;STFA_MSLcode,&lt;BR /&gt;lower(trim(STFA_MSLcode)) as STFA_MSLCode_key,&lt;BR /&gt;STFA_SoliMaKey_cnt,&lt;BR /&gt;STFA_SoliMaKey as STFA_ImpactedSolima,&lt;BR /&gt;STFA_ItemCleaned,&lt;BR /&gt;IF(LEN(FirstRecoverydate)=0,'NA',FirstRecoverydate) as FirstRecoverydate,&lt;BR /&gt;LastRecoverydate,&lt;BR /&gt;STFA_OSLastReplanDate,&lt;BR /&gt;MaxLastReplanDt,&lt;BR /&gt;CalFirstMatRecoveryDate,&lt;BR /&gt;(if((LastRecoverydate=FirstRecoverydate), 0,&lt;BR /&gt;if(LastRecoverydate&amp;gt;FirstRecoverydate,&lt;BR /&gt;(NetWorkDays(Date(left(FirstRecoverydate,10),'YYYY-MM-DD')-1,Date(left(LastRecoverydate,10),'YYYY-MM-DD'))),&lt;BR /&gt;((NetWorkDays(Date(left(LastRecoverydate,10),'YYYY-MM-DD')-1,Date(left(FirstRecoverydate,10),'YYYY-MM-DD')))*(-1))))) AS MatRecoveryDiff&lt;/P&gt;&lt;P&gt;Resident CTSUniqueLineMapping&lt;BR /&gt;order by cts_unique_order_line,STFA_MSLcode,STFA_OSLastReplanDate,STFA_SoliMaKey;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(STFA_T1)&lt;BR /&gt;Load Distinct cts_unique_order_line,&lt;BR /&gt;STFA_Material as STFA_MCP1,&lt;BR /&gt;if(MatRecoveryDiff&amp;lt;-3.0,'Material Early',&lt;BR /&gt;if((MatRecoveryDiff&amp;lt;=0.0 AND MatRecoveryDiff&amp;gt;=-3.0),'Material Ontime' ,&lt;BR /&gt;if(MatRecoveryDiff&amp;gt;0.0,'Material delay'))) as [STFA Root Cause 1]&lt;BR /&gt;Resident STFA_T1&lt;BR /&gt;where(CalFirstMatRecoveryDate = FirstRecoverydate);&lt;/P&gt;&lt;P&gt;Left Join(STFA_T1)&lt;BR /&gt;Load Distinct cts_unique_order_line,&lt;BR /&gt;if((FirstRecoverydate = 'NA' or CalFirstMatRecoveryDate = 'NA'),'NA',STFA_MCP1) as STFA_MCP&lt;BR /&gt;Resident STFA_T1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(STFA_T1)&lt;BR /&gt;Load Distinct cts_unique_order_line,&lt;BR /&gt;STFA_Material as STFA_MCP_Last1,&lt;BR /&gt;if(MatRecoveryDiff&amp;lt;-3.0,'Material Early',&lt;BR /&gt;if((MatRecoveryDiff&amp;lt;=0.0 AND MatRecoveryDiff&amp;gt;=-3.0),'Material Ontime' ,&lt;BR /&gt;if(MatRecoveryDiff&amp;gt;0.0,'Material delay'))) as [STFA Root Cause Last]&lt;BR /&gt;Resident STFA_T1&lt;BR /&gt;where STFA_OSLastReplanDate = MaxLastReplanDt;&lt;/P&gt;&lt;P&gt;Left Join(STFA_T1)&lt;BR /&gt;Load Distinct cts_unique_order_line,&lt;BR /&gt;if(LastRecoverydate = 'NA','NA',STFA_MCP_Last1) as STFA_MCP_Last&lt;BR /&gt;Resident STFA_T1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left Join(STFA_T1)&lt;BR /&gt;Load Distinct&lt;BR /&gt;cts_unique_order_line,&lt;BR /&gt;if(IsNull(MatRecoveryDiff) AND MatRecoveryDiff&amp;lt;&amp;gt;'0','First MCP is not available', //DATE(LastWorkDate(STFA_ItemCleaned, 3))&amp;gt;STFA_OSLastReplanDate and&lt;BR /&gt;if((CalFirstMatRecoveryDate = FirstRecoverydate OR LastRecoverydate = FirstRecoverydate),[STFA Root Cause 1],&lt;BR /&gt;'First MCP is not available, last MCP is available')) as [STFA Root Cause]&lt;BR /&gt;Resident STFA_T1 ;&lt;/P&gt;&lt;P&gt;DROP Table CTSUniqueLineMapping;&lt;BR /&gt;DROP Field [STFA Root Cause 1];&lt;/P&gt;&lt;P&gt;Left Join(STFA_T1)&lt;BR /&gt;LOAD cts_unique_order_line, max(STFA_SoliMaKey_cnt) as STFA_SoliMaKey_MaxCnt&lt;BR /&gt;Resident STFA_T1 Group by cts_unique_order_line;&lt;/P&gt;&lt;P&gt;Left Join(STFA_T1)&lt;BR /&gt;LOAD cts_unique_order_line, Concat(DISTINCT STFA_MSLCode_key,'|') as STFA_All_MSLCode_key&lt;BR /&gt;Resident STFA_T1 Group by cts_unique_order_line;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;STFA_T2:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;LOAD *,&lt;BR /&gt;if(RowNo()=1,1,Peek(RowIndex)+1) as RowIndex,&lt;BR /&gt;if(wildmatch(STFA_All_MSLCode_key,'*ww supply issue*') ,'ww supply issue',&lt;BR /&gt;if(wildmatch(STFA_All_MSLCode_key,'*forecast*'),'forecast',&lt;BR /&gt;if(wildmatch(STFA_All_MSLCode_key,'*supplier issue*'),'supplier issue',STFA_All_MSLCode_key))) as STFA_Preference_MSLCode&lt;BR /&gt;Resident STFA_T1;&lt;/P&gt;&lt;P&gt;DROP Table STFA_T1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Left join(STFA_T2)&lt;BR /&gt;LOAD cts_unique_order_line, STFA_MCP, RowIndex, STFA_MSLcode, STFA_ImpactedSolima,MatRecoveryDiff,&lt;BR /&gt;FirstRecoverydate, LastRecoverydate, STFA_ItemCleaned, [STFA Root Cause]&lt;/P&gt;&lt;P&gt;Resident STFA_T2&lt;BR /&gt;where STFA_Preference_MSLCode=STFA_MSLCode_key and STFA_SoliMaKey_cnt=STFA_SoliMaKey_MaxCnt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Inner Join(STFA_T2)&lt;BR /&gt;LOAD cts_unique_order_line,&lt;BR /&gt;min(RowIndex) as RowIndex&lt;BR /&gt;Resident STFA_T2&lt;BR /&gt;Group by cts_unique_order_line;&lt;/P&gt;&lt;P&gt;DROP Field RowIndex;&lt;/P&gt;&lt;P&gt;EXIT SCRIPT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 09:32:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776233#M717836</guid>
      <dc:creator>rakeshkumar1890</dc:creator>
      <dc:date>2021-01-21T09:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise Code</title>
      <link>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776257#M717837</link>
      <description>&lt;P&gt;The first thing I would do is split the parts with a distinct clause.&lt;/P&gt;&lt;P&gt;Its better to load distinct into a temp table, then do any operations on a second load statement.&lt;/P&gt;&lt;P&gt;Distinct is supposedly a single threaded operation (I've heard people saying contrary to this so I'm not saying it as fact), but I do know a distinct clause will cause all complex operations on the same load statement to run incredibly slowly (e.g. joins, order by, group by, if statements).&lt;/P&gt;&lt;P&gt;Edit: I forgot to mention that the distinct needs to be completely separate load statement, a preceding load doesn't get out the performance hole of the distinct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the Ifs, most appear to be if this is less/greater so probably not much we can do there.&lt;/P&gt;&lt;P&gt;I did spot one - "&lt;SPAN&gt;IF(LEN(FirstRecoverydate)=0,'NA',FirstRecoverydate)&amp;nbsp;&lt;/SPAN&gt;", could this be replaced with an ALT() function?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 11:05:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776257#M717837</guid>
      <dc:creator>MikeA</dc:creator>
      <dc:date>2021-01-21T11:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise Code</title>
      <link>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776382#M717838</link>
      <description>&lt;P&gt;Hi Mike&lt;/P&gt;&lt;P&gt;Thanks for&amp;nbsp; your suggestion.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 15:25:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Optimise-Code/m-p/1776382#M717838</guid>
      <dc:creator>rakeshkumar1890</dc:creator>
      <dc:date>2021-01-21T15:25:44Z</dc:date>
    </item>
  </channel>
</rss>

