<?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: What makes a variable expression valid? in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445396#M97645</link>
    <description>&lt;P&gt;Can you explain what you mean by incorrect? are you getting a syntax error in the UI or an error when you try to run the script?&lt;BR /&gt;&lt;BR /&gt;From first glance you have a second closing bracket here which should cause an error:&lt;BR /&gt;&lt;SPAN&gt;Let vLastExecDate = peek('date', 0, 'table_name')&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Apr 2024 17:29:29 GMT</pubDate>
    <dc:creator>BenjaminT</dc:creator>
    <dc:date>2024-04-26T17:29:29Z</dc:date>
    <item>
      <title>What makes a variable expression valid?</title>
      <link>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445394#M97644</link>
      <description>&lt;P&gt;I am not sure what defines a valid expression for variables in the data load editor:&lt;/P&gt;
&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INCORRECT:&amp;nbsp; Let vLastExecDate = max(date);&lt;/P&gt;
&lt;P&gt;CORRECT: Let vLastExecDate = peek('date', 0, 'table_name'));&lt;BR /&gt;&lt;BR /&gt;OR&lt;/P&gt;
&lt;P&gt;INCORRECT: LET vIsS3TablePresent = NoOfRows('check_s3')&amp;gt;0;&lt;/P&gt;
&lt;P&gt;INCORRECT: LET vIsS3TablePresent = if(NoOfRows('check_s3')&amp;gt;0, 1, 0);&lt;/P&gt;
&lt;P&gt;What am I missing? This is an issue I face every month and I haven't pinned down what makes an expression valid for LET variable creation method.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 17:24:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445394#M97644</guid>
      <dc:creator>prayner</dc:creator>
      <dc:date>2024-04-26T17:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: What makes a variable expression valid?</title>
      <link>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445396#M97645</link>
      <description>&lt;P&gt;Can you explain what you mean by incorrect? are you getting a syntax error in the UI or an error when you try to run the script?&lt;BR /&gt;&lt;BR /&gt;From first glance you have a second closing bracket here which should cause an error:&lt;BR /&gt;&lt;SPAN&gt;Let vLastExecDate = peek('date', 0, 'table_name')&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 17:29:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445396#M97645</guid>
      <dc:creator>BenjaminT</dc:creator>
      <dc:date>2024-04-26T17:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: What makes a variable expression valid?</title>
      <link>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445461#M97653</link>
      <description>&lt;P&gt;Your incorrect expressions are returning null. A variable with a null or empty value at the end script execution will not get copied to the UI, so it appears that the variable "isn't created".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Max(date) returns null because Qlik doesn't know what "date" is. P&lt;SPAN&gt;eek('date', 0, 'table_name') "works" because you are fetching a specific value from a table. It is somewhat illogical to me because you are applying Max() to a single value. If you want to get the max value of the field named "date" into a variable it's a two step process -- a LOAD followed by a Peek():&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;LOAD Max(date) as Maxdate Resident table_name;&lt;BR /&gt;LET&amp;nbsp;vLastExecDate = Peek('MaxDate');&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This approach can be slow if you have a lot of rows in "table_name". A faster method that only reads the distinct values of date is:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;LOAD Max(FieldValue('date', RecNo())) as MaxDate&lt;BR /&gt;AutoGenerate FieldValueCount('date');&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NoOfRows('tablename') returns null if the table doesn't exist. (Admittedly it would be sweet if the &lt;A href="https://help.qlik.com/en-US/sense/February2024/Subsystems/Hub/Content/Sense_Hub/Scripting/TableFunctions/NoOfRows.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; mentioned this).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A working expression to test for the existence of a table is:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="p1"&gt;&lt;SPAN class="s1"&gt;LET&lt;/SPAN&gt; vIsS3TablePresent = &lt;SPAN class="s1"&gt;Alt&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;NoOfRows&lt;/SPAN&gt;('&lt;SPAN&gt;check_s3&lt;/SPAN&gt;'),-1)&amp;gt;-1;&lt;/PRE&gt;
&lt;P class="p1"&gt;If you need to test that the table exists and also has more than 0 rows then&amp;nbsp;&lt;/P&gt;
&lt;PRE class="p1"&gt;&lt;SPAN class="s1"&gt;LET&lt;/SPAN&gt; vIsS3TablePresent = &lt;SPAN class="s1"&gt;Alt&lt;/SPAN&gt;(&lt;SPAN class="s1"&gt;NoOfRows&lt;/SPAN&gt;('&lt;SPAN&gt;check_s3&lt;/SPAN&gt;'),-1)&amp;gt;0;&lt;/PRE&gt;
&lt;P class="p1"&gt;Lots of scripting blog posts and downloadable examples on my website&amp;nbsp;&lt;A href="https://qlikviewcookbook.com/" target="_blank" rel="noopener"&gt;https://qlikviewcookbook.com/&lt;/A&gt;.&lt;/P&gt;
&lt;P class="p1"&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/18172"&gt;@ChristofSchwarz&lt;/a&gt;&amp;nbsp;, aka "Dr Qlik-Script" is also &lt;A href="https://www.linkedin.com/pulse/qlik-script-join-christof-schwarz-cssjf/" target="_blank" rel="noopener"&gt;blogging&lt;/A&gt; regularly about Qlik Scripting. Christof and I will be doing some joint presentation on Qlik Script tips at the &lt;A href="https://masterssummit.com/" target="_blank" rel="noopener"&gt;Masters Summit for Qlik&lt;/A&gt; in September. Maybe we'll do a "tip-off".&lt;/P&gt;
&lt;P class="p1"&gt;-Rob&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2024 01:17:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/What-makes-a-variable-expression-valid/m-p/2445461#M97653</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2024-04-27T01:17:55Z</dc:date>
    </item>
  </channel>
</rss>

