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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Silvia2
Contributor II
Contributor II

Count by maximum date

Hi!

I have a table with the following fields:

Sequence Error_Code Date

Seq1            0                       23/11/2020

Seq1            101                  24/11/2020

Seq2            600                 09/05/2020

Seq2            0                      10/05/2020

Seq3            101                 09/12/2020

Seq3            0                      10/12/2020

 

I would like to count all the sequences from maximum date which have Error_Code=0

For the example only the Seq2 and Seq3 will be counted

1 Solution

Accepted Solutions
rubenmarin
MVP
MVP

Hi, this expression may do the work: 

Sum(Aggr(If(Date=Max(TOTAL <Sequence> Date) and Error_Code=0,1),Sequence,Date))

View solution in original post

5 Replies
rubenmarin
MVP
MVP

Hi, this expression may do the work: 

Sum(Aggr(If(Date=Max(TOTAL <Sequence> Date) and Error_Code=0,1),Sequence,Date))

Silvia2
Contributor II
Contributor II
Author

Thank you!
And to count the sequences with Error_Code different than 0 how should I have to modify the expression?

Sum(Aggr(If(Date=Max(TOTAL <Sequence> Date) and Error_Code=-0,1),Sequence,Date)) does not work and Sum(Aggr(If(Date=Max(TOTAL <Sequence> Date) and Error_Code>0,1),Sequence,Date)) gives wrong result

rubenmarin
MVP
MVP

Hi, try with: Sum(Aggr(If(Date=Max(TOTAL <Sequence> Date) and Error_Code<>0,1),Sequence,Date))

Silvia2
Contributor II
Contributor II
Author

Hi!

Still not working fine

When I make a selection, my values change and I don't understand why

The results are calculated correctly only when i make a selection(2nd photo)

Silvia2_0-1636717218983.png

Silvia2_1-1636717227604.png

 

rubenmarin
MVP
MVP

Hi, hard to guess, maybe something with the date model behind. If you could upload a sample that simulates your model with some dummy data to test, I can take a look.