Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Create variables through script

Hi guys, I have a problem with variables.

I'm trying to create a master calendar, this is the code:

  1. Temp: 
  2. Load 
  3.                min(OrderDate) as minDate, 
  4.                max(OrderDate) as maxDate 
  5. Resident Orders; 
  6. Let varMinDate = Num(Peek('minDate', 0, 'Temp')); 
  7. Let varMaxDate = Num(Peek('maxDate', 0, 'Temp')); 
  8. DROP Table Temp; 
  9. TempCalendar: 
  10. LOAD 
  11.                $(varMinDate) + Iterno()-1 As Num, 
  12.                Date($(varMinDate) + IterNo() - 1) as TempDate 
  13.                AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate); 
  14. MasterCalendar: 
  15. Load 
  16.                TempDate AS OrderDate, 
  17.                week(TempDate) As Week, 
  18.                Year(TempDate) As Year, 
  19.                Month(TempDate) As Month, 
  20.                Day(TempDate) As Day, 
  21.                YeartoDate(TempDate)*-1 as CurYTDFlag, 
  22.                YeartoDate(TempDate,-1)*-1 as LastYTDFlag, 
  23.                inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12, 
  24.                date(monthstart(TempDate), 'MMM-YYYY') as MonthYear, 
  25.                ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter, 
  26.                Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear, 
  27.                WeekDay(TempDate) as WeekDay 
  28. Resident TempCalendar 
  29. Order By TempDate ASC; 
  30. Drop Table TempCalendar;

The problem is at row 13th, because when I create a variables at rows 7th and 8th, these are <NULL>.


So I tested the code at rows 3th and 4th, and the code doesn't work.


Why I can not extract min and max values from the table?


Let me give you an example.


Thanks for the help

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

or use as below...

Temp:

    Load

     Min(Date(Date#(OrderDate,'DD/MM/YY'))) as minDate,

     Max(Date(Date#(OrderDate,'DD/MM/YY'))) as maxDate

Resident Orders;

View solution in original post

3 Replies
MK_QSL
MVP
MVP

Just change the variable as below in main tab

SET DateFormat='DD/MM/YY';

MK_QSL
MVP
MVP

or use as below...

Temp:

    Load

     Min(Date(Date#(OrderDate,'DD/MM/YY'))) as minDate,

     Max(Date(Date#(OrderDate,'DD/MM/YY'))) as maxDate

Resident Orders;

Anonymous
Not applicable
Author

Maybe the OrderDate not being read as a date so use the date and date# functions on your Orders table that loads prior to the code above.


Date(Date#(OrderDate,'DD/MM/YYYY'),'DD/MM/YYYY') as OrderDate