Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
dimak123
Partner - Contributor III
Partner - Contributor III

Autogenerate Dates fir inline load

Hi to all

I have a table:   

MachineShiftProduction
1Morning250
1Noon250
1Evening250
2Morning242
2Noon242
2Evening242
3Morning150
3Noon150
3Evening150
4Morning120
4Noon120
4Evening120
5Morning65
5Noon65
5Evening65
6Morning225
6Noon225
6Evening225
7Morning180
7Noon180
7Evening180
8Morning914
8Noon914

I would like to add a field of date from 01/01/2014 till yesterday every load

how do i write this?

thanks a head

1 Solution

Accepted Solutions
crusader_
Partner - Specialist
Partner - Specialist

Hi,

Do you really want to make Cartesian product?

For every Machine and Shift add full range of dates...

If so just pick part of master calendar code and JOIN it to your table

LET vMinDate = Num('01/01/2014');

LET vMaxDate = Num(Today() - 1);

TempCalendar:

JOIN(YourTable)

LOAD

  Date($(vMinDate) + IterNo() - 1) as Date

AutoGenerate 1 While $(vMinDate) + IterNo() -1 <= $(vMaxDate);


I can't imagine where it could be useful but you are free to choose...

Regards,

Andrei

View solution in original post

6 Replies
sunny_talwar

You can create a Master Calendar for dates, but how do you plan to connect your above table to the master calendar? There are no dates in the above table.

Script for Master Calendar:

LET vMinDate = Num('01/01/2014');

LET vMaxDate = Num(Today() - 1);

TempCalendar:

LOAD

  $(vMinDate) + IterNo() - 1 as Num,

  Date($(vMinDate) + IterNo() - 1) as TempDate

AutoGenerate 1 While $(vMinDate) + IterNo() -1 <= $(vMaxDate);

[Master Calendar]:

LOAD

  TempDate as Date,

  Week(TempDate) as Week,

  Year(TempDate) as Year,

  Month(TempDate) as Month,

  Day(TempDate) as Day,

  Weekday(TempDate) as WeekDay,

  WeekStart(TempDate) as WeekStart,

  'Q' & ceil(month(TempDate) / 3) as Quarter,

  'Q' & Ceil(Month(TempDate)/3) & '-' & Year(TempDate) as QuarterYear,

  MonthName(TempDate) as MonthYear,

  Week(TempDate)&'-'&Year(TempDate) as WeekYear

Resident TempCalendar

Order By TempDate ASC;

DROP Tables Temp, TempCalendar;

LET vMinDate = Null();

LET vMaxDate = Null();

HTH

Best,

Sunny

dimak123
Partner - Contributor III
Partner - Contributor III
Author

Hi

I dont need a master calendar

i just want to add date to my table, as the number of machines and shifts for every date

sunny_talwar

For each Machine, shift, production you want to add ~500 days????

dimak123
Partner - Contributor III
Partner - Contributor III
Author

yes

crusader_
Partner - Specialist
Partner - Specialist

Hi,

Do you really want to make Cartesian product?

For every Machine and Shift add full range of dates...

If so just pick part of master calendar code and JOIN it to your table

LET vMinDate = Num('01/01/2014');

LET vMaxDate = Num(Today() - 1);

TempCalendar:

JOIN(YourTable)

LOAD

  Date($(vMinDate) + IterNo() - 1) as Date

AutoGenerate 1 While $(vMinDate) + IterNo() -1 <= $(vMaxDate);


I can't imagine where it could be useful but you are free to choose...

Regards,

Andrei

dimak123
Partner - Contributor III
Partner - Contributor III
Author

thanks