Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Insert record in LinkTable where values match one of two Key fields

Hi everyone,

I'm not a QlikView Developer, but have taken over Administrative responsibilities of later. I've been struggling with this for a couple days, and figured it was time to stop sprinting backwards.

Our application uses a star schema with everything joining to a LinkTable. The LinkTable contains two Keys to dimension tables: Key|Reseller and Key|ReferralSystems.

All data is loaded from SQL tables into the LinkTable, and at the end of the script, we load data from an Excel spreadsheet containing Client and Goal information.

The IdClient in the spreadsheet can be associated with one of four options:

  1. Single Reseller
  2. Single ReferralSystem
  3. Multiple Resellers
  4. Multiple ReferralSystems

To simplify the logic, we can declare that if an IdReseller exists, we should use that and ignore the ReferralSystemId.

Additionally, to support the one-to-many relationship between a Client record and Resellers/ReferralSystems, we have some table records with GoalAmounts blank to avoid double-counting Goals in the application

An example of the Excel spreadsheet is below:

IdClientClientDateIdResellerReferralSystemIdGoal
1Client AJan201567662
1Client AFeb201567662
1Client AMar201567662
1Client AApr201567672
1Client AMay201567672
1Client AJun201567672
1Client AJul201567672
1Client AAug201567682
1Client ASep201567682
1Client AOct201567682
1Client ANov2015676102
1Client ADec201567652
2Client BJan201515305
2Client BFeb2015
15308
2Client BMar201515311
2Client BApr201515314
2Client BMay201515317
2Client BJun201515321
2Client BJul201515324
2Client BAug201515327
2Client BSep201515330
2Client BOct201515334
2Client BNov201515337
2Client BDec201515340
2Client BJan201516
2Client BFeb2015
16
2Client BMar201516
2Client BApr201516
2Client BMay201516
2Client BJun201516
2Client BJul201516
2Client BAug201516
2Client BSep201516
2Client BOct201516
2Client BNov201516
2Client BDec201516

       

The Excel spreadsheet is being read twice into two separate different tables (ApptsBookedGoals for Client and Goal info and ClientLink as a temp table for all Reseller/ReferralSystem/Client associations):

ApptsBookedGoals:

LOAD Distinct

     IdReseller & '_' & ReferralSystemId as Key|Client,

     Client,

     Date as GoalDate,

     Goal as GoalAmount

FROM

[Data\Goal line for QV.xlsx]

(ooxml, embedded labels, table is Sheet1)

where len(trim(Goal)) > 0;

ClientLink:

LOAD Distinct

     IdClient,

     IdReseller as CL.IdReseller,

     ReferralSystemId as CL.ReferralSystemId

FROM

[Data\Goal line for QV.xlsx]

(ooxml, embedded labels, table is Sheet1);

What I need to do at this point is left join on the LinkTable to insert IdClient (as Key|Client) whenever:

  1. Key|Resellers from LinkTable matches CL.IdReseller OR
  2. Key|ReferralSystemId from LinkTable matches CL.ReferralSystemId

My most recent attempt was to add if(isnull()) logic in the left join to pass null as Key|ReferralSystems whenever Key|Resellers is valid (and vice versa for Key|Resellers):

Left Join (LinkTable)

LOAD

  If(IsNull(Key|Resellers)=0,

  NULL(),

  Key|Resellers)

  as Key|Resellers,

  If(IsNull(Key|Resellers)=0,

  Key|ReferralSystems,

  NULL())

  as Key|ReferralSystems,

  If(IsNull(Key|Resellers)=0,

  ApplyMap('MapRefSys',Key|ReferralSystems,'NULL'),

  ApplyMap('MapReseller',Key|Resellers,'NULL'))

  as Key|Client

Resident LinkTable;

Since QV joins on all fields with matching field names, this logic will not work.

Please help guide me out of the snake pit and towards the sunlight!

0 Replies