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: 
alexdelagarza
Contributor II
Contributor II

Count if a user has not one but two possible values

Hello,

I have the following table:

USER Scenario
IMDM26963748 A
IMDM24755867 A
IMDM27296460 A
IMDM22749898 A
IMDM23681226 A
IMDM23681226 B
IMDM28166404 A
IMDM28166404 B
IMDM25781532 A
IMDM25781532 B
IMDM28134074 A
IMDM28134074 B
IMDM26799093 A
IMDM26861096 A
IMDM24102807 A
IMDM27644821 A

 

I need to count only the users that has both scenarios A and B.

I've tried the following:

Try 1:

= Count( {<Escenario2 = {100},Escenario2 = {101}>}USER)

But it counts 16 instead of 4 which is the correct answer.

 

Try 2:

= Count( {<Scenario={'A','B'}>}USER)

Same result than Try 1.

 

Thanks!

Labels (1)
1 Solution

Accepted Solutions
MatheusC
Specialist
Specialist

@alexdelagarza 
Use with the P() element function, represent the set of possible values:

count( {$<USER= P({1<Scenario={'A'}>})*P({1<Scenario={'B'}>})>} distinct USER )


- Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!

View solution in original post

5 Replies
Chernov
Creator
Creator

Count( {<Escenario2 = {100}>*<Escenario2 = {101}>}USER)

Intersection operator = *

 

https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/SetAnalys...

MatheusC
Specialist
Specialist

@alexdelagarza 
Use with the P() element function, represent the set of possible values:

count( {$<USER= P({1<Scenario={'A'}>})*P({1<Scenario={'B'}>})>} distinct USER )


- Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
alexdelagarza
Contributor II
Contributor II
Author

Hello Chernov,

Thanks for your reply, It still counting all the lines (16), I'm attaching the test file.

Best

alexdelagarza
Contributor II
Contributor II
Author

Hi Matheus,

I tried your function and it gave me another result (504)

Then I tried your function omitting the number 1, as follows:

=count( {$<ID_CARD= P({<Escenario2={'100'}>})*P({<Escenario2={'101'}>})>} distinct ID_CARD )

And it work, this function gave me the expected result (24)

To be honest I just try omitting the number one without knowing what I was doing.

Now I can continue with other scenarios to check if it still works.

Thanks!

 

MatheusC
Specialist
Specialist

As a complement to explanation. The function P() returns the possible values, so it can be affected by the user's selection. The identifier 1 is used to ignore all user selections.

I am happy to help,
- Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!