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

employee shortages control

Hi!

I have a table like this:

PersonStartDateEndDate
Ktrsa12016-01-012016-01-02
Ktrsa12016-01-052016-01-10

And a table calendar by dates.

I need create a sheet like this:

table.png

Any idea?

Tks

1 Solution

Accepted Solutions
sunny_talwar

You will need to use Interval Match to make this to work: IntervalMatch

See if the blog makes sense

Check the sample out:

Script:

Table:

LOAD * Inline [

Person, StartDate, EndDate

Ktrsa1, 2016-01-01, 2016-01-02

Ktrsa1, 2016-01-05, 2016-01-10

];

MinMax:

LOAD Min(StartDate) as MinDate,

  Max(EndDate) as MaxDate

Resident Table;

LET varMinDate = Peek('MinDate');

LET varMaxDate = Peek('MaxDate');

DROP Table MinMax;

QuartersMap: 

MAPPING LOAD  

rowno() as Month, 

'Q' & Ceil (rowno()/3) as Quarter 

AUTOGENERATE (12); 

TempCalendar: 

LOAD $(varMinDate) + Iterno()-1 As Num, 

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

     AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate); 

 

MasterCalendar: 

Load TempDate AS Date, 

     week(TempDate) As Week, 

     Year(TempDate) As Year, 

     Month(TempDate) As Month, 

     Day(TempDate) As Day, 

     YeartoDate(TempDate)*-1 as CurYTDFlag, 

     YeartoDate(TempDate,-1)*-1 as LastYTDFlag, 

     inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12, 

     date(monthstart(TempDate), 'MMM-YYYY') as MonthYear, 

     ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter, 

     Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear, 

     WeekDay(TempDate) as WeekDay 

Resident TempCalendar 

Order By TempDate ASC; 

Drop Table TempCalendar;

Left Join(Table)

IntervalMatch(Date)

LOAD StartDate,

  EndDate

Resident Table;

Output:

Capture.PNG

View solution in original post

2 Replies
sunny_talwar

You will need to use Interval Match to make this to work: IntervalMatch

See if the blog makes sense

Check the sample out:

Script:

Table:

LOAD * Inline [

Person, StartDate, EndDate

Ktrsa1, 2016-01-01, 2016-01-02

Ktrsa1, 2016-01-05, 2016-01-10

];

MinMax:

LOAD Min(StartDate) as MinDate,

  Max(EndDate) as MaxDate

Resident Table;

LET varMinDate = Peek('MinDate');

LET varMaxDate = Peek('MaxDate');

DROP Table MinMax;

QuartersMap: 

MAPPING LOAD  

rowno() as Month, 

'Q' & Ceil (rowno()/3) as Quarter 

AUTOGENERATE (12); 

TempCalendar: 

LOAD $(varMinDate) + Iterno()-1 As Num, 

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

     AutoGenerate 1 While $(varMinDate) + IterNo() -1 <= $(varMaxDate); 

 

MasterCalendar: 

Load TempDate AS Date, 

     week(TempDate) As Week, 

     Year(TempDate) As Year, 

     Month(TempDate) As Month, 

     Day(TempDate) As Day, 

     YeartoDate(TempDate)*-1 as CurYTDFlag, 

     YeartoDate(TempDate,-1)*-1 as LastYTDFlag, 

     inyear(TempDate, Monthstart($(varMaxDate)),-1) as RC12, 

     date(monthstart(TempDate), 'MMM-YYYY') as MonthYear, 

     ApplyMap('QuartersMap', month(TempDate), Null()) as Quarter, 

     Week(weekstart(TempDate)) & '-' & WeekYear(TempDate) as WeekYear, 

     WeekDay(TempDate) as WeekDay 

Resident TempCalendar 

Order By TempDate ASC; 

Drop Table TempCalendar;

Left Join(Table)

IntervalMatch(Date)

LOAD StartDate,

  EndDate

Resident Table;

Output:

Capture.PNG

MarcoARaymundo
Creator III
Creator III
Author

Tks Sunny T.