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

Calculate distinct number of names from a row based on multiple dimension values

Hi All,

I need to calculate the number of staff allocated to each sessions (based on the unique "Room" and the "Session_Start" combination).

Please find the below base data set,

Trainee NoTrainee NameStaff 1Staff 2Staff 3RoomSession_StartDate
100MarkMatt  Room-012/10/2018 14:302/10/2018
101AntonSylan  Room-023/10/2018 10:303/10/2018
102AndrewMattSylan Room-012/10/2018 14:302/10/2018
103AshScod  Room-035/10/2018 10:305/10/2018
104PrishScodBrenden Room-0112/10/2018 14:3012/10/2018
105DavidMattSylanBrendenRoom-012/10/2018 10:302/10/2018
101AntonSylan  Room-035/10/2018 10:305/10/2018
103AshScodBrenden Room-012/10/2018 14:302/10/2018
105DavidScod  Room-0116/10/2018 14:3016/10/2018
101AntonPaul  Room-012/10/2018 10:302/10/2018
100MarkScodBrenden Room-035/10/2018 10:305/10/2018
101AntonSylan  Room-0116/10/2018 14:3016/10/2018
105DavidScodSylan Room-0110/10/2018 14:3010/10/2018

 

As depicted above,  each session will have number of Trainee Staff and assigned Staff members for the training programs.

My requirement is to calculate the total number of allocated staff for each session (considering the unique key as the combination of "Room" and "Session_Start") and construct an outcome table as shown below;

SessionSession_StartNumber of Staff
Room-012/10/2018 10:304
Room-012/10/2018 14:304
Room-0110/10/2018 14:302
Room-0112/10/2018 14:302
Room-0116/10/2018 14:302
Room-023/10/2018 10:301
Room-035/10/2018 10:303

 

Appreciate, if someone could help me in this regards. 

Note

I can perform the data load part and the grouping of the "Trainee No" based on the "Room" and the "Session_Start" field but not so sure how to use the SET analysis to accomplish the above requirement using an expression.

Look forward to hearing from you.

Thank you in advance.

Kind regards,

Andy

 

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

RangeSum(count(DISTINCT [Trainee No]),count(DISTINCT [Staff 1]),
Count(DISTINCT [Staff 2]), Count(DISTINCT [Staff 3]))Capture.JPG

 

 

 

View solution in original post

4 Replies
tresesco
MVP
MVP

If you could use crosstable() and transform your table, set analysis might not be required. PFA

 

CrossTable(StaffType, StaffName, 3)
LOAD Room,
Session_Start,
Date,
[Trainee Name],
[Staff 1],
[Staff 2],
[Staff 3]

FROM
[Staff Allocation.xlsx]
(ooxml, embedded labels, table is [Group Activity]);Capture.JPG

 

 

 

andymanu
Creator II
Creator II
Author

Hi Tresesco,
Thanks for your reply.
Actually, I can't convert my straight table in to a cross table cos I got some other fields as well.
Additionally, I am also adding few fields using ApplyMap function.
Thus, appreciate if I could use an expression may be using set analysis and get the desired outcome.
Look forward to hearing from you.
Thanks.
Kind regards,
Andy
tresesco
MVP
MVP

Try like:

RangeSum(count(DISTINCT [Trainee No]),count(DISTINCT [Staff 1]),
Count(DISTINCT [Staff 2]), Count(DISTINCT [Staff 3]))Capture.JPG

 

 

 

andymanu
Creator II
Creator II
Author

Hi Tresesco,
Thank you very much.
Both methods worked fine and I only had to change the qualifier field number.
Also, only had to remove the Count(DISTINCT [Trainee No]) from the range expression.
Thank you a lot once again.
Kind regards,
Andrew