Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Saravanan_Desingh

Self Join kind-of

Hello-

I have a situation here.

Let my Data is like this.

 

EmpMgrCity
e1m1c1
e2m1c1
e3m1c2
m1m2c3
e4m2c2
m2m3c1
m3m1

c3

I need the output like this:

 

MgrCityCount
m1c34
m2c12
m3c31

Basically, Manager's City and Head Count under him. I know, AGGR like functions can help in doing Self-Join. But not good in that subject. Can someone help me? thank you.

1 Solution

Accepted Solutions
MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_198753_Pic1.JPG

QlikCommunity_Thread_198753_Pic4.JPG

QlikCommunity_Thread_198753_Pic2.JPG

QlikCommunity_Thread_198753_Pic3.JPG

tabEmp:

Hierarchy(Emp,Mgr,EmpName,,Emp,'EmpPath',,)

LOAD Emp,

    Emp as EmpName,

    Mgr,

    City

FROM [https://community.qlik.com/thread/198753] (html, codepage is 1252, embedded labels, table is @1);

Left Join (tabEmp)

LOAD Emp as Mgr,

    City as MgrCity

Resident tabEmp;

DROP Fields EmpName;

The hierarchy load isn't necessary to get your expected result but might add additional selection (treeview) and visualization possibilities to your application.

The difference in the employee count for m2 compared to your expected result is caused by a loop in your sample data, i.e. m2 can't have his manager's manager as an employee (m1->m3->m2->m1).

hope this helps

regards

Marco

View solution in original post

5 Replies
sunny_talwar

May be this?

Capture.PNG

Saravanan_Desingh
Author

No, Sunny.

For m2 & m3, City is wrong. We have to see Mgr in Emp Column and then take the corresponding City.

MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_198753_Pic1.JPG

QlikCommunity_Thread_198753_Pic4.JPG

QlikCommunity_Thread_198753_Pic2.JPG

QlikCommunity_Thread_198753_Pic3.JPG

tabEmp:

Hierarchy(Emp,Mgr,EmpName,,Emp,'EmpPath',,)

LOAD Emp,

    Emp as EmpName,

    Mgr,

    City

FROM [https://community.qlik.com/thread/198753] (html, codepage is 1252, embedded labels, table is @1);

Left Join (tabEmp)

LOAD Emp as Mgr,

    City as MgrCity

Resident tabEmp;

DROP Fields EmpName;

The hierarchy load isn't necessary to get your expected result but might add additional selection (treeview) and visualization possibilities to your application.

The difference in the employee count for m2 compared to your expected result is caused by a loop in your sample data, i.e. m2 can't have his manager's manager as an employee (m1->m3->m2->m1).

hope this helps

regards

Marco

Saravanan_Desingh
Author

Nice learning for me. Thanks Marco.

MarcoWedel

you're welcome

please close your thread if your question is answered.

thanks

regards

Marco