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: 
Not applicable

Count duplicate values

Hello everybody!

how can i count duplicate values in the script?

Example:

MyTable

Col 1Col 2
a1
a2
a2
a3
b1
b1

After counting i need this output:

Col 1Col 2Col 3
a11
a22
a31
b12

Thank You!

1 Reply
Not applicable
Author

The easiest way I saw to do this was to create a key of Col1&Col2.  That way you can perform a count on that key and store the result as Col3.

In the script I did:

Table1:

LOAD * INLINE

[

Col1, Col2

a, 1

a, 2

a, 2

a, 3

b, 1

b, 1

];

Table2:

LOAD *,

Col1&Col2 as ColKey,

' ' as Junk1

Resident Table1

;

Drop table Table1;

Table3:

LOAD Col1,

           Col2,

     Count(ColKey) as Col3

Resident Table2

GROUP BY ColKey,Col1,Col2;

Drop table Table2;

The resulting set desired is in Table3.

I also have attached a .qvw in case you need extra reference.

Hope this helps!