Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
david777
Contributor II
Contributor II

Count values regardless selection

Hello,

I have the following table.

VisitIDPersonIDYEAR
112014
212015
312016
412017
512018
612018
722015
822016
922017
1032016
1132017
1232017
1332018
1442014
1542015
1642015
1742016
1842018
1952016
2052016


I want to count how many PersonID who had at least two VisitID during the period 2017-2018.

The answer should be 2 (PersonID 1 and PersonID 3) even if I make the selection 2018 for field YEAR.

Can anyone help me with this?


Best regards

1 Solution

Accepted Solutions
john_obrien
Contributor III
Contributor III

David,

This expression (also shown in the gauge chart below) works for me:

     Sum(If( Aggr( Count ( {<YEAR = {2017,2018}>} VisitID), PersonID)>=2,1,0) )

aggr example.png

It may not be the most efficient way to calculate it, but it may be fine for a small data set.

View solution in original post

3 Replies
sergio0592
Specialist III
Specialist III

Hi, it works with :

=count({<PersonID={"=count({<YEAR={'2017','2018'}>} VisitID)>2"}>} distinct PersonID)

john_obrien
Contributor III
Contributor III

David,

This expression (also shown in the gauge chart below) works for me:

     Sum(If( Aggr( Count ( {<YEAR = {2017,2018}>} VisitID), PersonID)>=2,1,0) )

aggr example.png

It may not be the most efficient way to calculate it, but it may be fine for a small data set.

shiveshsingh
Master
Master

Hi

check with this, values will not change even if you select 2018 in YEAR column

=count({<YEAR,PersonID={"=Count({<YEAR={'2017','2018'}>}VisitID)>2"}>}distinct PersonID)