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

Count unique values from a CrossTable() column

Hi All,

The question is part of the discussion posted on the below link.

https://community.qlik.com/t5/New-to-Qlik-Community/Calculate-distinct-values-from-rows-based-on-mul...

I want to calculate the count of unique values from a CrossTable column.

The answer provided by Jontydkpi

STAFF 1STAFF 2STAFF 3STAFF 4
Millar, PatrickCooper, David (Assistant 1)Millar, Patrick (Manager)Mills, Peter (Assistant Coordinator)

 

One of the concern I got is the  "comma" (",") which separates the first name and the last name.

The expected outcome from the above row should be 3 Staff Members ( cos the STAFF 1 and STAFF 3 referred to the same member) instead of 4. Sometimes a staff member could have only his/her name(filed STAFF 1) or the name followed by the designation(filed STAFF 3).  Thus, the retrieving of the unique staff number should consider  name on the Field STAFF 1 against the any other field which got the Staff names.

I use the CrossTable() function and the below code to calculate the unique Staff Numbers

SubField([Staff 1], ' ', 1) as [Staff 1],

The above returns an answer of 4 Staff instead of 3.

I may be missing here. But really appreciate, if some one (may be Jontydkpior Tresesco) could help me to fix this issue.

Thank you in advance.

Kind regards,

Andy

 

1 Solution

Accepted Solutions
andymanu
Creator II
Creator II
Author

Hi All,
I think I got the answer for the above question after playing around the code.
I simply changed the "SubField([Staff 1], ' ', 1) as [Staff 1]," statement to "SubField([Staff 1], ' (', 1) as [Staff 1], by adding a "(" so that the qlik will not consider anything after the "(" opening bracket.
Not sure whether this is an efficient way of doing the task, but it worked.
Thanks.
Kind regards,
Andy

View solution in original post

1 Reply
andymanu
Creator II
Creator II
Author

Hi All,
I think I got the answer for the above question after playing around the code.
I simply changed the "SubField([Staff 1], ' ', 1) as [Staff 1]," statement to "SubField([Staff 1], ' (', 1) as [Staff 1], by adding a "(" so that the qlik will not consider anything after the "(" opening bracket.
Not sure whether this is an efficient way of doing the task, but it worked.
Thanks.
Kind regards,
Andy