Skip to main content
Announcements
Do More with Qlik - Qlik Cloud Analytics Recap and Getting Started, June 19: REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Scripting - Intervalmatch

Good morning,

Let´s assume there are two tables

a) HolidayHours, with fields EmployeeNr, Date, NrHours

b) EmployeeMaster, with fields EmployeeNr, DateFrom, DateTo, CostCenter

EmployeeMaster has records starting from say 2011, while HolidayHours has records starting say 2013. The script should deliver as a result one or several tables showing records from EmployeeMaster ONLY for dates in HolidayHours (for example, no EmployeeMaster records with DateTo before 2013).

I script

*******************

load * from HolidayHours;

load * from EmployeeMaster;

BridgeTable:

IntervalMatch ( Date, EmployeeNr)
Load distinct DateFrom, DateTo,, EmployeeNr Resident EmployeeMaster;
left join (HolidayHours)
load * resident BridgeTable
where len(trim(Date)>=0;

drop BridgeTable;

*******************

The IntervalMatch and LeftJoin work as I expect i.e. I get a table where I have a single matching record from EmployeeMaster for every HolidayHours record. However, I still have records from EmployeeMaster that do not match any HolidayHours record - how can I get rid of those?

Many thanks in advance,

Leonardo

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Try

Inner Join (HolidayHours)

IntervalMatch(Date, EmployeeNr)

Load ValidFrom, ValidTo, EmployeeNr Resident EmployeeMaster;

Left Join (HolidayHours)

Load * Resident EmployeeMaster;

Drop Table EmployeeMaster;

View solution in original post

12 Replies
tresesco
MVP
MVP

Perhaps, you have to use Right Join rather than left join.

MK_QSL
MVP
MVP

Use Right Join or Outer Join rather than Left Join in your application..

Not applicable
Author

Thanks for your suggestion. As a result, I want to see records from EmployeeMaster only if they match records from HolidayHours, isn´t that what Left Join (HolidayHours) is supposed to do?

In any case, trying Right Join or Outer Join for a single EmployeeNr doesn´t change the outcome at least for the individual EmployeeNr I´m using as a test.

As a beginner, I am under the impression that the join statement is joining HolidayHours with BridgeTable not with EmployeeMaster. Since Intervalmatch is using ( Date, EmployeeNr) as key, guess it also uses a value where EmployeeNr is not blank but Date isn´t?

Any other suggestions?

MK_QSL
MVP
MVP

Can you provide both tables with some dummy data... say around 10-10 lines only in excel file?

tresesco
MVP
MVP

Intervalmatch() is supposed to take one argument. Have you checked if the generated tables are getting linked with a synthetic key or disconnected?

Not applicable
Author

An example is

EmployeeMaster

EmployeeNrValidToValidFromCompanyCodeCostCenter
471128.06.201201.04.20111501507009180
471131.12.201229.06.20121501507009182
471131.12.999901.01.20131501507009184
987631.01.201301.01.20131011016009010
987631.12.999901.02.20131011016009011
123430.09.201101.04.20111041043493570
123431.12.201101.10.20111041043493571
123431.12.201201.01.20121041043493572
123431.05.201401.01.20131041043493573
123431.12.999901.06.20141041043493574

HolidayHours

EmployeeNrDateNrHours
123406.09.201396
123408.10.201396
123407.11.201348
123407.12.201348
123431.12.201316
123431.01.2014240
123428.02.2014240
123431.03.2014240
123430.04.2014240
123430.05.2014224
123430.06.2014216
123431.07.2014184
987631.08.2013128
987630.09.2013128
987631.10.2013120
987630.11.2013120
987631.12.201396
987631.01.2014320
987628.02.2014320
987631.03.2014320
987630.04.2014208
987631.05.2014192
987630.06.2014192
987631.07.2014192

And the script is

LOAD EmployeeNr,
    
Date,
    
NrHours

FROM
HolidayHours.xls
(
txt, unicode, embedded labels, delimiter is '\t', msq);

Directory;
LOAD EmployeeNr,
    
ValidTo,
    
ValidFrom,
    
CompanyCode,
    
CostCenter

FROM
EmployeeMaster.XLS
(
txt, unicode, embedded labels, delimiter is '\t', msq);

BridgeTable:
IntervalMatch ( Date, EmployeeNr)
Load distinct ValidFrom, ValidTo, EmployeeNr Resident EmployeeMaster;

Left Join (HolidayHours)
load * resident BridgeTable
WHERE len(trim(Date))>1;

drop table BridgeTable;

Not applicable
Author

Hi Tresesco,

the tables get linked with a synthetic key,

Best regards,

Leonardo

tresesco
MVP
MVP

I would still stick to my earlier opinion, the issue possibly with wrong number of arguments  in intervalmatch(); it should be one. Beyond that, I really could not understand your requirement. Could you post your expected output against the provided sample data?

Not applicable
Author

The result should be a table with all records from HolidayHours and only the matching records from EmployeeMaster. In below table, the records with a blank Date are not OK, the others are OK:

CostCenterEmployeeNrValidFromValidToDateNrHours
1043493570123401.04.201130.09.2011--
1043493571123401.10.201131.12.2011--
1043493572123401.01.201231.12.2012--
1043493573123401.01.201331.05.201406.09.201396
1043493573123401.01.201331.05.201408.10.201396
1043493573123401.01.201331.05.201407.11.201348
1043493573123401.01.201331.05.201407.12.201348
1043493573123401.01.201331.05.201431.12.201316
1043493573123401.01.201331.05.201431.01.2014240
1043493573123401.01.201331.05.201428.02.2014240
1043493573123401.01.201331.05.201431.03.2014240
1043493573123401.01.201331.05.201430.04.2014240
1043493573123401.01.201331.05.201430.05.2014224
1043493574123401.06.201431.12.999930.06.2014216
1043493574123401.06.201431.12.999931.07.2014184
------