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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
reema_dangwal
Contributor
Contributor

Aggregate functionality in set expression

Hi All,

Need help with the following query:

I have a table with columns as - incidents, groups and dates.
I need to count the number of incidents per week. However need to count only those incidents in a week which are more than 2 when grouped by group.

Please suggest how this can be achieved, can we use aggr function inside set expression?

PFA the data excel file and sample Qvw.

Example:

As shown below, this is how counts are represented per week.

weekcount(Incidents)
64
12/28/20151
2/1/20161
2/29/20166
3/7/20167
3/14/20167
3/21/20167
3/28/20167
4/4/20167
4/11/20167
4/18/20167
4/25/20167

but for week starting 2/29/2016, we have 6 incidents, in which 3 are from Group A, 2 - Group B and 1 - Group C.
So we need to show the count as 3 for 2/29/2016, since only Group A has a count more than 2.

 

114Group A01-03-2016
115Group A02-03-2016
116Group A03-03-2016
117Group B04-03-2016
118Group B05-03-2016
119Group C06-03-2016

Thanks

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe like attached, using a WeekGroupKey field created in the script and set analysis in your expression.

Weekstart count({<WeekGroupKey = {"=Count(Incidents)>2"}>} Incidents)
59
2/29/20163
3/7/20167
3/14/20167
3/21/20167
3/28/20167
4/4/20167
4/11/20167
4/18/20167
4/25/20167

View solution in original post

3 Replies
swuehl
MVP
MVP

Maybe like attached, using a WeekGroupKey field created in the script and set analysis in your expression.

Weekstart count({<WeekGroupKey = {"=Count(Incidents)>2"}>} Incidents)
59
2/29/20163
3/7/20167
3/14/20167
3/21/20167
3/28/20167
4/4/20167
4/11/20167
4/18/20167
4/25/20167
reema_dangwal
Contributor
Contributor
Author

Thanks Stefan, it works. However when i tried to implement the same on a bi-weekly basis, I am getting vague results.

PFA the test qvw file.

  The following incidents are falling under week - 2/15/2016 however they should fall under 2/29/2016.

Week        Incidents    Date          Group

2/15/20161143/1/2016Group A
2/15/20161153/2/2016Group A
2/15/20161163/3/2016Group A
2/15/20161173/4/2016Group B

I tried with date formatting too, not working.In order to represent date on a bi-weekly basis, shall I use something else apart from class function?

swuehl
MVP
MVP

I think you need the correct offset for your rounding / classifying, which should be any weekstart, not date(0), a saturday.

table:

LOAD *,

Weekstart(Floor(date,14,weekstart(Makedate(2000)))) as Weekstart,

AutoNumberHash256(Group, Weekstart(Floor(date,14,weekstart(Makedate(2000)))) ) as WeekGroupKey;

LOAD Incidents,

     Group,

     date

FROM

dummy.xlsx

(ooxml, embedded labels, table is Sheet1);