<?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 Help Please: Variable Assignment Not Working? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205160#M61763</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I went through my code, and my notes, and I've found what was giving me grief when I tried to use the peek function. I'm not sure it's applicable though.&lt;/P&gt;&lt;P&gt;In my load script, I was loading a field from a SQL database called 'currentTime'; for some reason, I could only reference it if I used all caps (ie: CURRENTIME) in the peek function. I think it had to do with the fact that I didn't use a full load statement, and failed to alias the field. I'd applied the alias in the SQL statement instead.&lt;/P&gt;&lt;P&gt;As a somewhat radical suggestion, try changing your alias names, and the reference in the peek function to all caps... see if that does anything for you.&lt;/P&gt;&lt;P&gt;Here's another code sample, again I use all caps. The other notable difference is that the table's name isn't in quotes. (thogh both of these sets of code work); With regard to the second part of the issue, (peeking at the last record didn't give you the max() date) just sort the table based on your date field first, and you should be fine. This example works with a sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;//Look into the cases object, and find out the min and max dates in it&lt;BR /&gt;LET varMinDate = num(peek('ORDER_DATE',0,Transactions));&lt;BR /&gt;LET varMaxDate = num(peek('ORDER_DATE',-1,Transactions));&lt;BR /&gt;LET varToday = num(today());&lt;BR /&gt;TempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(varMinDate) + rowno() - 1 AS Num,&lt;BR /&gt; date($(varMinDate) + rowno() - 1) AS TDATE&lt;BR /&gt;AUTOGENERATE&lt;BR /&gt; $(varMaxDate) - $(varMinDate) + 1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;BR /&gt; &lt;I&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;For some reason, in all cases, I'm explicitly casting the results from the peek function, eitehr to a date, or to a number. I don't know if that is relevant, but it's interesting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Jun 2010 17:02:11 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-06-29T17:02:11Z</dc:date>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205155#M61758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm trying to create a calendar based on a table extracted from our Microsoft SQL Server Support Database (the "Incident_Management" table. The first LOAD statement (ClosedDateRange) works fine and retrtieves a single row with the numeric value of the first and last Closed dates for all our Support Calls, however the LET statements immediately following do not retrieve any values causing all the subsequent LOADs to fail.&lt;/P&gt;&lt;P&gt;Has anyone seen this where a variable assignment does not retrieve a value even though there is only a single row in the resident tables with data in each field?&lt;/P&gt;&lt;P&gt;Any pointers greatly appreciated.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;P&gt;The calendar tab in my script looks as follows:&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;ClosedDateRange:&lt;BR /&gt;LOAD&lt;BR /&gt; min(ClosedDate) AS FirstClosedDate,&lt;BR /&gt; max(ClosedDate) AS LastClosedDate&lt;BR /&gt;RESIDENT Incident_Management;&lt;/P&gt;&lt;P&gt;LET vn_StartDate = peek('FirstClosedDate',-1,'ClosedDateRange')-1;&lt;BR /&gt;LET vn_EndDate = peek('LastClosedDate',-1,'ClosedDateRange');&lt;BR /&gt;LET vn_DateRange = $(vn_EndDate) - $(vn_StartDate);&lt;/P&gt;&lt;P&gt;//Drop table ClosedDateRange;&lt;/P&gt;&lt;P&gt;QUALIFY *;&lt;/P&gt;&lt;P&gt;CallsClosedTempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(vn_StartDate)+recno() as TempDate&lt;BR /&gt;autogenerate $(vn_DateRange);&lt;/P&gt;&lt;P&gt;UNQUALIFY ClosedDate;&lt;/P&gt;&lt;P&gt;CallsClosedCalendar:&lt;BR /&gt;LOAD CallsClosedTempCalendar.TempDate AS ClosedDate,&lt;BR /&gt; Week(CallsClosedTempCalendar.TempDate) AS Week,&lt;BR /&gt; Year(CallsClosedTempCalendar.TempDate) AS Year,&lt;BR /&gt; Month(CallsClosedTempCalendar.TempDate) AS Month,&lt;BR /&gt; Day(CallsClosedTempCalendar.TempDate) AS Day,&lt;BR /&gt; Weekday(CallsClosedTempCalendar.TempDate) AS WeekDay,&lt;BR /&gt; 'Q' &amp;amp; Ceil(Month(CallsClosedTempCalendar.TempDate) / 3) AS Quarter,&lt;BR /&gt; Date(MonthStart(CallsClosedTempCalendar.TempDate), 'MMM-YYYY') AS MonthYear,&lt;BR /&gt; Week(CallsClosedTempCalendar.TempDate) &amp;amp; '-' &amp;amp; Year(CallsClosedTempCalendar.TempDate) AS WeekYear&lt;BR /&gt;RESIDENT CallsClosedTempCalendar&lt;BR /&gt;ORDER BY CallsClosedTempCalendar.TempDate ASC;&lt;/P&gt;&lt;P&gt;//STORE * FROM CallsClosedCalendar INTO eSD_Calls_Closed_Calendar.qvd;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 15:37:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205155#M61758</guid>
      <dc:creator />
      <dc:date>2010-06-28T15:37:20Z</dc:date>
    </item>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205156#M61759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;check you fogot While there..&lt;/P&gt;&lt;PRE style="margin:0px;"&gt;CallsClosedTempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(vn_StartDate)+recno() as TempDate&lt;BR /&gt;autogenerate $(vn_DateRange)&lt;BR /&gt;while ($(vn_StartDate) + iterno()-1 &amp;lt;=$(vn_StartDate))&lt;BR /&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 15:45:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205156#M61759</guid>
      <dc:creator />
      <dc:date>2010-06-28T15:45:23Z</dc:date>
    </item>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205157#M61760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi sravan,&lt;/P&gt;&lt;P&gt;According to the example I was referring to from the SiB workshop I don't need the "while" because $(vn_DateRange) is supposed to tell autogenerate how many dates to create. $(vn_DateRange) would be calculated from $(vn_EndDate) - $(vn_StartDate).&lt;/P&gt;&lt;P&gt;My problem is that the LET statements aren't retrieving any values from the ClosedDateRange table. The was the example I was given on the workshop course:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;// Dynamic Date range is built from data field - Date registered - change as required&lt;BR /&gt;// Replace all instances of MyDate with the key date field&lt;BR /&gt;// Replace instance of MyTable with the key date field resident table name&lt;BR /&gt;// All generated date fields will be prefaced with Cal_&lt;BR /&gt;Range:&lt;BR /&gt;LOAD&lt;BR /&gt; min(Date) as startdate,&lt;BR /&gt; max(Date) as enddate&lt;BR /&gt;resident InvoiceHeader;&lt;BR /&gt;//Peek out the values for later use&lt;BR /&gt;let vStart = peek('startdate',-1,'Range')-1;&lt;BR /&gt;let vEnd = peek('enddate',-1,'Range');&lt;BR /&gt;let vRange = $(vEnd) - $(vStart);&lt;BR /&gt;//Remove Range table as no longer needed&lt;BR /&gt;Drop table Range;&lt;BR /&gt;//Generate a table with a row per date between the range above&lt;BR /&gt;Date:&lt;BR /&gt;Load&lt;BR /&gt; $(vStart)+recno() as Date&lt;BR /&gt;autogenerate $(vRange);&lt;BR /&gt;//Calculate the Parts you need to examine&lt;BR /&gt;Calendar:&lt;BR /&gt;load&lt;BR /&gt; Date as Date,&lt;BR /&gt;// date(Date,'dd/mm/yyyy') as Cal_FullDate,&lt;BR /&gt; Year(Date) as CalendarYear,&lt;BR /&gt; 'Q'&amp;amp;ceil(Month(Date)/3) AS Cal_Quarter,&lt;BR /&gt;// right(yearname(Date,0,$(vFiscalMonthStart)),4) as Cal_FiscalYear,&lt;BR /&gt;// if(InYear (Date, today(), -1),1) as Cal_FULL_LY, // All Dates Last Year&lt;BR /&gt;// if(InYear (Date, today(), 0),1) as Cal_FULL_TY, // All Dates This Year&lt;BR /&gt; if(InYearToDate (Date, today(), 0),1,0) as Cal_YTD_TY, // All Dates to Date this Year&lt;BR /&gt; if(InYearToDate (Date, today(), -1),1,0) as Cal_YTD_LY, // All Dates to Date Last Year&lt;BR /&gt;&lt;BR /&gt; if(InQuarterToDate (Date, today(), 0),1,0) as Cal_QTR_TQ,&lt;BR /&gt; if(InQuarterToDate (Date, today(), -1),1,0) as Cal_QTR_LQ,&lt;BR /&gt;&lt;BR /&gt; if(InMonthToDate(Date, today(), 0),1,0) as Cal_MNTH_TM,&lt;BR /&gt; if(InMonthToDate(Date, today(), -1),1,0) as Cal_MNTH_LM,&lt;BR /&gt;&lt;BR /&gt;// YTD_LY, used in Expressions Ex. Sum(Sales*YTD_LY)&lt;BR /&gt; quartername(Date) as Cal_CalendarQuarter,&lt;BR /&gt;// quartername(Date,0,$(vFiscalMonthStart)) as Cal_FiscalQuarter,&lt;BR /&gt;// Month(Date)&amp;amp;'-'&amp;amp;right(yearname(Date,0,11),4) as Cal_FiscalMonthYear, //Fiscal!&lt;BR /&gt; Month(Date)&amp;amp;'-'&amp;amp;right(year(Date),4) as Cal_MonthYear,&lt;BR /&gt; Month(Date) as Cal_Month,&lt;BR /&gt; Day(Date) as Cal_Day,&lt;BR /&gt; Week(Date) as Cal_Week,&lt;BR /&gt; Weekday(Date) as Cal_WeekDay&lt;BR /&gt;resident Date;&lt;BR /&gt;//Tidy up&lt;BR /&gt;Drop table Date;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jun 2010 15:56:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205157#M61760</guid>
      <dc:creator />
      <dc:date>2010-06-28T15:56:05Z</dc:date>
    </item>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205158#M61761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your script, you're always peeking at the -1th record. I would expect that in a table containing only 1 row that it shouldn't matter if you used 0, or -1 as the first record (0) is the last (-1). However, I've been surprised by a couple of QlikView oddities, so in this case, I would suggest trying to peek() at the first record (0)&lt;/P&gt;&lt;P&gt;I have to do the same thing in several of my load scripts.&lt;/P&gt;&lt;P&gt;If this doesn't work, what happens when you step through? are these variables being assigned any value at all? or do they remain 'null'?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jun 2010 01:00:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205158#M61761</guid>
      <dc:creator />
      <dc:date>2010-06-29T01:00:10Z</dc:date>
    </item>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205159#M61762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ryan,&lt;/P&gt;&lt;P&gt;Many thanks for your reply. I have already tried using 0 in the peek statements but they still return NULL. When stepping through in the debugger, the following messages are generated:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;ScriptErrorCount 2&lt;BR /&gt;ScriptErrorDetails "Table not found"&lt;BR /&gt;ScriptErrorList General Error Table Not Found&lt;BR /&gt;ScriptError Table Not Found&lt;BR /&gt;autogenerate &amp;lt;NULL&amp;gt;&lt;BR /&gt;vn_DateRange &amp;lt;NULL&amp;gt;&lt;BR /&gt;vn_StartDate &amp;lt;NULL&amp;gt;&lt;BR /&gt;- &amp;lt;NULL&amp;gt;&lt;BR /&gt;vn_EndDate &amp;lt;NULL&amp;gt;&lt;BR /&gt;DayNames "Mon;Tue;Wed;Thu;Fri;Sat;Sun"&lt;BR /&gt;MonthNames "Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec"&lt;BR /&gt;TimestampFormat "DD/MM/YYYY hh:mm:ss[.fff]"&lt;BR /&gt;DateFormat "DD/MM/YYYY"&lt;BR /&gt;TimeFormat "hh:mm:ss"&lt;BR /&gt;MoneyFormat "£#,##0.00;-£#,##0.00"&lt;BR /&gt;MoneyDecimalSep "."&lt;BR /&gt;MoneyThousandSep ","&lt;BR /&gt;DecimalSep "."&lt;BR /&gt;ThousandSep ","&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;It is almost as if the peek function is not working at all. I'm very confused.&lt;/P&gt;&lt;P&gt;Before I started trying this approach to building the calendar, I tried to get the Start and End dates by peek-ing directly into the Incident_Management table. Start Date was retrieved successfully but the End Date was always NULL unless I changed -1 to -2 or something else. Of course this didn't help because the End Date retrieved was not the last date in the table.&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jun 2010 09:50:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205159#M61762</guid>
      <dc:creator />
      <dc:date>2010-06-29T09:50:46Z</dc:date>
    </item>
    <item>
      <title>Help Please: Variable Assignment Not Working?</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205160#M61763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I went through my code, and my notes, and I've found what was giving me grief when I tried to use the peek function. I'm not sure it's applicable though.&lt;/P&gt;&lt;P&gt;In my load script, I was loading a field from a SQL database called 'currentTime'; for some reason, I could only reference it if I used all caps (ie: CURRENTIME) in the peek function. I think it had to do with the fact that I didn't use a full load statement, and failed to alias the field. I'd applied the alias in the SQL statement instead.&lt;/P&gt;&lt;P&gt;As a somewhat radical suggestion, try changing your alias names, and the reference in the peek function to all caps... see if that does anything for you.&lt;/P&gt;&lt;P&gt;Here's another code sample, again I use all caps. The other notable difference is that the table's name isn't in quotes. (thogh both of these sets of code work); With regard to the second part of the issue, (peeking at the last record didn't give you the max() date) just sort the table based on your date field first, and you should be fine. This example works with a sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;//Look into the cases object, and find out the min and max dates in it&lt;BR /&gt;LET varMinDate = num(peek('ORDER_DATE',0,Transactions));&lt;BR /&gt;LET varMaxDate = num(peek('ORDER_DATE',-1,Transactions));&lt;BR /&gt;LET varToday = num(today());&lt;BR /&gt;TempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(varMinDate) + rowno() - 1 AS Num,&lt;BR /&gt; date($(varMinDate) + rowno() - 1) AS TDATE&lt;BR /&gt;AUTOGENERATE&lt;BR /&gt; $(varMaxDate) - $(varMinDate) + 1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt; &lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;BR /&gt; &lt;I&gt;&lt;/I&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;For some reason, in all cases, I'm explicitly casting the results from the peek function, eitehr to a date, or to a number. I don't know if that is relevant, but it's interesting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jun 2010 17:02:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Please-Variable-Assignment-Not-Working/m-p/205160#M61763</guid>
      <dc:creator />
      <dc:date>2010-06-29T17:02:11Z</dc:date>
    </item>
  </channel>
</rss>

