Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
spinchuk
Partner - Contributor III
Partner - Contributor III

How to connect two tables?

I'm drawing blank on what seems to be a simple concept...

Let's say we have 2 tables: FactSales and DimEmployee:

ConsultantKeySalesPersonKeyValue
1210
3210
1310
EmployeeKeyEmployeeName
1John Smith
2Ann Smith
3Bob Write

What is the best way to connect these two tables?

Both ConsultantKey and SalesPersonKey correspond to the EmployeeKey.

Thank you!

6 Replies
Gysbert_Wassenaar

The best way is to not connect them, but to map the keys to names:

EmpMap:

mapping load EmployeeKey, EmployeeName

From DimEmployeeSource;

FactSales:

Load *

     , applymap('EmpMap',ConsultantKey) as ConsultantName

     , applymap('EmpMap',SalesPersonKey) as SalesPersonName

From FactSalesSource;


talk is cheap, supply exceeds demand
Not applicable

May be you can try creating three tables in total like this;

Fact:

Load ConsultantKey,

         SalesPersonKey,

         Value

From Table;

Dim1:

Load EmployeeKey as ConsultantKey,

        EmployeeName as ConsultantName

From Table;

Dim2:

Load EmployeeKey as SalesPersonKey,

        EmployeeName as SalesPersonName

From Table;

spinchuk
Partner - Contributor III
Partner - Contributor III
Author

Thank you Gysbert,

while your solution works for the example above, my question is more about the modeling concept, since I have many other attributes of employee (such as employee type, tier, cost, state, etc.). So mapping everything into the fact table does not seem to make sense. Any other suggestion?

Thank you!

Gysbert_Wassenaar

Use Ajay's solution


talk is cheap, supply exceeds demand
Anonymous
Not applicable

I think that the solution that Henric Cronström suggested for the calendar can be used in this case for Employee:

http://community.qlik.com/blogs/qlikviewdesignblog/2014/02/17/canonical-date

User can select an employee name, and a flag, let's call it "Role", specifying that he wants to see the facts records of this employee as a Consultant or as a Sales Person.

spinchuk
Partner - Contributor III
Partner - Contributor III
Author

Thank you everyone for your recommendations!

The solution that I chose is to split DimEmployee table into two: Consultant and SalesPerson.

Please find the code attached (thank you Igor!)

Please comment if you feel that there is yet another solution.