Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
Creator III
Creator III

Count over several rows

Hi,

I have a rather large table with the following dimensions:

IDGroupYearLocLocCountStatus
123R2012ABC3A
123R2013ABC5A
123R2014ABC2A
123R2015ABC3A
45612012ABC1C
45612013ABC-C
45612014ABC3C
45612015ABC2C
789R2012DEF-D
789R2013DEF6D
789R2014DEF1D
789R2015DEF2D
789R2012GHI1E
789R2013GHI1E
789R2014GHI-E
789R2015GHI-E

From this, I want an expression for the 'Status' column using the following criteria (in the hierarchical order shown below):

A - If the LocCount for the ID, Group and Loc is at least 2 in every year

B - If the LocCount for the ID, Group and Loc is at least 1 in every year

C - If the LocCount for the ID, Group and Loc is at least 2 in 2015 and 2014

D - If the LocCount for the ID, Group and Loc is at least 1 in 2015 and 2014

E - If above criteria not met for any ID, Group and Loc

I've completed the status column in the example above with what I would expect to see.

What's the best way to achieve this? In the script or by expression only?

Help would be really appreciated on this as I'm on a very tight schedule and not sure where to start!!

24 Replies
jessica_webb
Creator III
Creator III
Author

Sorry Sunny - doing a rubbish job at multitasking today!

Ok, FG should be 'D' - there is at least 1 in 2016 and 1 in 2015

sunny_talwar

Try this

If(Count(TOTAL <ID, Group, Loc>Year) = 3,

    If(Min(TOTAL <ID, Group, Loc> Alt(LocCount, 0)) = 2, 'A',

    If(Min(TOTAL <ID, Group, Loc> Alt(LocCount, 0)) = 1, 'B', 'E')),

If(Count(TOTAL <ID, Group, Loc>{<Year = {2016, 2015}>}Year) = 2,

    If(Min(TOTAL <ID, Group, Loc> {<Year = {2016, 2015}>} Alt(LocCount, 0)) = 2, 'C',

    If(Min(TOTAL <ID, Group, Loc> {<Year = {2016, 2015}>} Alt(LocCount, 0)) = 1, 'D', 'E')), 'E'))

For when Loc = '-', we have three years, so it falls under status 'B'

Capture.PNG

jessica_webb
Creator III
Creator III
Author

Fantastic

You have saved my weekend!!!

I'm struggling to get it working in the script though. I'm using:

LEFT Join (TABLE)

LOAD

ID,

Group,

Loc,,

LocCount

Year,

If(Count(TOTAL <ID, Group, Loc>Year) = 3,

    If(Min(TOTAL <ID, Group, Loc> Alt(LocCount, 0)) = 2, 'A',

    If(Min(TOTAL <ID, Group, Loc> Alt(LocCount, 0)) = 1, 'B', 'E')),

If(Count(TOTAL <ID, Group, Loc>{<Year = {2016, 2015}>}Year) = 2,

    If(Min(TOTAL <ID, Group, Loc> {<Year = {2016, 2015}>} Alt(LocCount, 0)) = 2, 'C',

    If(Min(TOTAL <ID, Group, Loc> {<Year = {2016, 2015}>} Alt(LocCount, 0)) = 1, 'D', 'E')), 'E')) as Status

Resident TABLE

Group By ID, Group, Loc;

sunny_talwar

TOTAL doesn't work in the script ....

sunny_talwar

Try this

Left Join (Table)

LOAD ID,

Group,

Loc,

If(Count(Year) = 3,

If(Min(Alt(LocCount, 0)) = 2, 'A',

If(Min(Alt(LocCount, 0)) = 1, 'B', 'E')),

If(Count(If(Match(Year, 2016, 2015), Year)) = 2,

If(Min(If(Match(Year, 2016, 2015), Alt(LocCount, 0))) = 2, 'C',

If(Min(If(Match(Year, 2016, 2015), Alt(LocCount, 0))) = 1, 'D', 'E')), 'E')) as Status

Resident Table

Group By ID, Group, Loc;