<?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 Peek returns &amp;lt;NULL&amp;gt; on count-attribute (Count &amp;amp; Peek issue) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Peek-returns-lt-NULL-gt-on-count-attribute-Count-amp-Peek-issue/m-p/1620479#M46185</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I ran into an issue where whatever I do I always get &amp;lt;NULL&amp;gt; values back. See the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For i=0 to (NoOfRows('CustomerAZT1')-1)&lt;BR /&gt;&lt;BR /&gt;Let currentCustomerID=Peek('CustomerID', $(i), 'CustomerAZT1');&lt;BR /&gt;Let currentCustomerEMail=Peek('CustomerEMail', $(i), 'CustomerAZT1');&lt;BR /&gt;&lt;BR /&gt;Set minYear=2018;&lt;BR /&gt;Set maxYear=year(now(0));&lt;BR /&gt;Set minMonth=1;&lt;BR /&gt;Set maxMonth=12;&lt;/P&gt;&lt;P&gt;For j=$(minYear) to $(maxYear)&lt;BR /&gt;For k=$(minMonth) to $(maxMonth)&lt;BR /&gt;t1:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;Load&lt;BR /&gt;Count(OrderEMail) as "NumberOfOrders"&lt;BR /&gt;Resident OrderAZ&lt;BR /&gt;Where year(OrderTimeStampAdded)&amp;amp;num(month(OrderTimeStampAdded))&amp;lt;=$(j)$(k) and $(currentCustomerID)=OrderCustomerID;&lt;BR /&gt;&lt;BR /&gt;Let currentNumberOfOrders=Peek('NumberOfOrders', 0, 't1');&lt;BR /&gt;Drop Table t1;&lt;BR /&gt;&lt;BR /&gt;Concatenate&lt;BR /&gt;LOAD * Inline [&lt;BR /&gt;'CustomerID', 'CustomerEMail', 'YearMonth', 'TotalNumberOfOrders', 'CustomerGroup'&lt;BR /&gt;$(currentCustomerID), $(currentCustomerEMail), $(j)$(k), $(currentNumberOfOrders), $(currentCustomerGroup)&lt;BR /&gt;];&lt;BR /&gt;&lt;BR /&gt;Next&lt;BR /&gt;Next&lt;BR /&gt;Next;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I count the number of orders for each customer. But somehow if there is no order for a customer, the "peek"-function returns &amp;lt;NULL&amp;gt; instead of 0.&lt;/P&gt;&lt;P&gt;Any ideas would be much apreciated. Thank you in advance for looking through my code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 20:08:18 GMT</pubDate>
    <dc:creator>erp_curaden</dc:creator>
    <dc:date>2024-11-16T20:08:18Z</dc:date>
    <item>
      <title>Peek returns &lt;NULL&gt; on count-attribute (Count &amp; Peek issue)</title>
      <link>https://community.qlik.com/t5/App-Development/Peek-returns-lt-NULL-gt-on-count-attribute-Count-amp-Peek-issue/m-p/1620479#M46185</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I ran into an issue where whatever I do I always get &amp;lt;NULL&amp;gt; values back. See the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For i=0 to (NoOfRows('CustomerAZT1')-1)&lt;BR /&gt;&lt;BR /&gt;Let currentCustomerID=Peek('CustomerID', $(i), 'CustomerAZT1');&lt;BR /&gt;Let currentCustomerEMail=Peek('CustomerEMail', $(i), 'CustomerAZT1');&lt;BR /&gt;&lt;BR /&gt;Set minYear=2018;&lt;BR /&gt;Set maxYear=year(now(0));&lt;BR /&gt;Set minMonth=1;&lt;BR /&gt;Set maxMonth=12;&lt;/P&gt;&lt;P&gt;For j=$(minYear) to $(maxYear)&lt;BR /&gt;For k=$(minMonth) to $(maxMonth)&lt;BR /&gt;t1:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;Load&lt;BR /&gt;Count(OrderEMail) as "NumberOfOrders"&lt;BR /&gt;Resident OrderAZ&lt;BR /&gt;Where year(OrderTimeStampAdded)&amp;amp;num(month(OrderTimeStampAdded))&amp;lt;=$(j)$(k) and $(currentCustomerID)=OrderCustomerID;&lt;BR /&gt;&lt;BR /&gt;Let currentNumberOfOrders=Peek('NumberOfOrders', 0, 't1');&lt;BR /&gt;Drop Table t1;&lt;BR /&gt;&lt;BR /&gt;Concatenate&lt;BR /&gt;LOAD * Inline [&lt;BR /&gt;'CustomerID', 'CustomerEMail', 'YearMonth', 'TotalNumberOfOrders', 'CustomerGroup'&lt;BR /&gt;$(currentCustomerID), $(currentCustomerEMail), $(j)$(k), $(currentNumberOfOrders), $(currentCustomerGroup)&lt;BR /&gt;];&lt;BR /&gt;&lt;BR /&gt;Next&lt;BR /&gt;Next&lt;BR /&gt;Next;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I count the number of orders for each customer. But somehow if there is no order for a customer, the "peek"-function returns &amp;lt;NULL&amp;gt; instead of 0.&lt;/P&gt;&lt;P&gt;Any ideas would be much apreciated. Thank you in advance for looking through my code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 20:08:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Peek-returns-lt-NULL-gt-on-count-attribute-Count-amp-Peek-issue/m-p/1620479#M46185</guid>
      <dc:creator>erp_curaden</dc:creator>
      <dc:date>2024-11-16T20:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: Peek returns &lt;NULL&gt; on count-attribute (Count &amp; Peek issue)</title>
      <link>https://community.qlik.com/t5/App-Development/Peek-returns-lt-NULL-gt-on-count-attribute-Count-amp-Peek-issue/m-p/1623402#M46424</link>
      <description>&lt;P&gt;I would suggest changing:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Let currentNumberOfOrders=Peek('NumberOfOrders', 0, 't1');&lt;/LI-CODE&gt;&lt;P&gt;to:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Let currentNumberOfOrders=Alt(Peek('NumberOfOrders', 0, 't1'),0);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason you are getting NULL is because the where clause is executing before the Count(). So the Count() function doesn't even get executed because it isn't fed any data, which results with a table with no rows. Try the test case below to see what I mean:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Test:
Load * Inline [
ID, Cat, Amt
1, A, 10
1, B, 20
2, C, 30
];


WhereTest:
Load
	'Test' 		as Note,
	Count(Amt) 	as Cnt
Resident
	Test
Where
	ID = 1 AND Cat = 'C';&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 18:48:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Peek-returns-lt-NULL-gt-on-count-attribute-Count-amp-Peek-issue/m-p/1623402#M46424</guid>
      <dc:creator>treysmithdev</dc:creator>
      <dc:date>2019-09-12T18:48:26Z</dc:date>
    </item>
  </channel>
</rss>

