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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Micki
Creator
Creator

Set expression - calculation based on state and id

Hi guys, Could please help, 

Could not build set expressions to calculate in the table only last state 'Active' when after was none State 'New' based on week date

 

Id StateSet expressionDate 
1Active0week1
1New week1
3Active 0week2
3New week2
5New week3
5Active1week3

 

Result should be 1 

Many thanks!

Could you please take a look @sunny_talwar ? 

Labels (1)
  • SaaS

1 Solution

Accepted Solutions
sunny_talwar

So, you can try one of the two

Sum(Aggr(
  If(FirstSortedValue(State, -TimeStampField) = 'Active', 1, 0)
, Id))

or

Count(DISTINCT {<Id = {"=FirstSortedValue(State, -TimeStampField) = 'Active'}>} Id)

 

View solution in original post

3 Replies
sunny_talwar

How do you determine if Active came first or New? Id and Date (week) seems to be same for both Active and New rows?

Micki
Creator
Creator
Author

Hi, sorry i didn't mention that instead of date i have Timestamp, so I sorted by ID + THEN week number based on Timestamp

sunny_talwar

So, you can try one of the two

Sum(Aggr(
  If(FirstSortedValue(State, -TimeStampField) = 'Active', 1, 0)
, Id))

or

Count(DISTINCT {<Id = {"=FirstSortedValue(State, -TimeStampField) = 'Active'}>} Id)