<?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: Can this be optimized? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514679#M192234</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kelly,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can achieve this by a Sub-Select in the Where clause:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13771090623913255" jivemacro_uid="_13771090623913255" modifiedtitle="true"&gt;
&lt;P&gt;SQL SELECT GL_Period__c FROM Invoice__c &lt;/P&gt;
&lt;P&gt;where GL_Period__c &amp;gt;= (SELECT max(GL_Period__c) FROM Invoice__c) -1;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - Ralf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Aug 2013 18:18:09 GMT</pubDate>
    <dc:creator>rbecher</dc:creator>
    <dc:date>2013-08-21T18:18:09Z</dc:date>
    <item>
      <title>Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514678#M192233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to perform a max() in the WHERE clause of an SQL statement without having to load the full table beforehand?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my example, I'd like to load the most current month's invoices as well as the previous month's. Typically the current month's invoices are not loaded until the 15th through 20th, so until the new ones are loaded I'll have to use the previous month and the month before that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: 1307 invoices not loaded --&amp;gt; pull 1306 and 1305. If 1307 is loaded, pull 1307 and 1306.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what I'm using currently:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;AllInvoices:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;SQL SELECT GL_Period__c&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;FROM Invoice__c;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;MaxGLPeriod:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;LOAD &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&amp;nbsp; max(num#(GL_Period__c)) as MaxGLPeriod,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&amp;nbsp; max(num#(GL_Period__c)) -1 as MaxGLPeriodLessOne&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;RESIDENT AllInvoices;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;LET vMaxGLPeriod = text(peek('MaxGLPeriod', 0, MaxGLPeriod));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;LET vMaxGLPeriodLessOne = text(peek('MaxGLPeriodLessOne',0,MaxGLPeriod));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;DROP TABLE MaxGLPeriod, AllInvoices;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;INVOICE:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;SQL SELECT &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GL_Period__c&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;FROM Invoice__c where GL_Period__c ='$(vMaxGLPeriod)' or GL_Period__c = '$(vMaxGLPeriodLessOne)';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;I know the above works, but I'd like to see if it's possible to remove the 1st SQL table and avoid creating a 2nd table.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was thinking something along the lines of below, but that doesn't compile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;INVOICE:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;SQL SELECT &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GL_Period__c&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;FROM Invoice__c where GL_Period__c =&lt;SPAN style="font-family: 'andale mono', times;"&gt;max(num#(GL_Period__c))&lt;/SPAN&gt; or GL_Period__c = &lt;SPAN style="font-family: 'andale mono', times;"&gt;max(num#(GL_Period__c)) -1&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Thoughts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 18:03:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514678#M192233</guid>
      <dc:creator>kkorynta</dc:creator>
      <dc:date>2013-08-21T18:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514679#M192234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kelly,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can achieve this by a Sub-Select in the Where clause:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13771090623913255" jivemacro_uid="_13771090623913255" modifiedtitle="true"&gt;
&lt;P&gt;SQL SELECT GL_Period__c FROM Invoice__c &lt;/P&gt;
&lt;P&gt;where GL_Period__c &amp;gt;= (SELECT max(GL_Period__c) FROM Invoice__c) -1;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; - Ralf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 18:18:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514679#M192234</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2013-08-21T18:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514680#M192235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see and that makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it still possible to use the conversion functions in the where clause? The GL_Period__c field is a text field in our source database, so originally I converted it to a number for the max() statement then converted it back to text for the WHERE clause (hence the A OR B).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried something like&lt;/P&gt;&lt;P&gt;WHERE GL_Period__c &amp;gt;=&amp;nbsp; '(SELECT max(GL_Period__c) FROM Invoice__c) -1';&lt;/P&gt;&lt;P&gt;and it pulled all of the invoices ever created.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 18:44:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514680#M192235</guid>
      <dc:creator>kkorynta</dc:creator>
      <dc:date>2013-08-21T18:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514681#M192236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You'll need a database conversion/cast function like to_number():&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13771165282411227" jivemacro_uid="_13771165282411227" modifiedtitle="true"&gt;
&lt;P&gt;SQL SELECT GL_Period__c FROM Invoice__c &lt;/P&gt;
&lt;P&gt;where GL_Period__c &amp;gt;= (SELECT max(&lt;STRONG&gt;to_number&lt;/STRONG&gt;(GL_Period__c)) FROM Invoice__c) -1;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 20:24:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514681#M192236</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2013-08-21T20:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514682#M192237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ralf,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I'm not able to get it working because I'm using the Salesforce connector which appears it has to follow these guidelines &lt;A href="http://www.salesforce.com/us/developer/docs/soql_sosl/" title="http://www.salesforce.com/us/developer/docs/soql_sosl/"&gt;Force.com SOQL and SOSL Reference&lt;/A&gt;. I'm still kind of new to SQL and SOQL so I wasn't even aware that in SQL you could cast/convert. It appears SOQL doesn't allow casting/converting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, great feedback! It'll definitely get put to use at some point. Thank you for your time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 20:56:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514682#M192237</guid>
      <dc:creator>kkorynta</dc:creator>
      <dc:date>2013-08-21T20:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Can this be optimized?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514683#M192238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And I thought you have a real database backend.. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case just use this SQL select statement and Load: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13771233592406215" jivemacro_uid="_13771233592406215"&gt;
&lt;P&gt;LOAD num#(max_period) as MaxGLPeriod, num#(max_period)-1 as MaxGLPeriodLessOne;&lt;/P&gt;
&lt;P&gt;SQL SELECT max(GL_Period__c) as max_period FROM Invoice__c&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SOQL max() aggregation function should work also on a varchar column period if it has the format YYMM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Ralf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Aug 2013 22:16:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-this-be-optimized/m-p/514683#M192238</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2013-08-21T22:16:28Z</dc:date>
    </item>
  </channel>
</rss>

