Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
jacek_k
Contributor III
Contributor III

How to count unique values

Date Code ID key
2022-05-01 A 1 A1
2022-02-01 A 2 A2
2022-02-01 B 1 B1
2022-02-01 B 1 B1

 

Hello, 

How to find (count) key only A1 or A2 or both. How to not count B1? 

I can count (key) = 4 or count (distinct key) = 3 but I need 2 ( just A values). Off course key value can be different. 

 

Labels (2)
1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

So the logic is: "Count all keys that don't have duplicates"?

Then you can use
Count({<key={"=Count(key)=1"}>} key)

View solution in original post

7 Replies
hic
Former Employee
Former Employee

Count({<key-={B1}>} key)

jacek_k
Contributor III
Contributor III
Author

Yes, but B1 Is example - it will be different values  

Andrei_Cusnir
Specialist
Specialist

Hello,

 

@Henric_Cronström is right! To elaborate further in the solution, here is the expressions on some test data:

 

1. Loaded all the data and added one extra row for B1 to see clearly the difference

2. Used the following expressions:

  • Count({<key={'A1'}>}key) // Count A1
  • Count({<key={'A2'}>}key) // Count A2
  • Count({1-<key={'B1'}>}key) // Count all except B1

3. Outcome is:

 

As you can see it counts all the needed values properly.

 

I hope that this information was helpful.

 

 

 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂
jacek_k
Contributor III
Contributor III
Author

Yes, you right but how to count without knowing the values?

sidhiq91
Specialist II
Specialist II

@jacek_k  Could you please be more clear with your requirement? The above methods should yield you the required output. Or provide us some sample data?

jacek_k
Contributor III
Contributor III
Author

I edit my post. The idea is count values except values where are the same (B1). Of course key will be different so I can not use -= .

hic
Former Employee
Former Employee

So the logic is: "Count all keys that don't have duplicates"?

Then you can use
Count({<key={"=Count(key)=1"}>} key)