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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

AGGR without taking into account the current selections

The scenario is:

RowID

Year

Month

Date

ID

Filter

1

2017

1

01/01/2017

A

1

2

2017

1

02/01/2017

A

0

3

2017

2

03/01/2017

A

0

4

2017

2

04/02/2017

B

1

5

2017

2

05/02/2017

B

0

I have two list boxes with year and month, when I select both I would like to know the numbers of IDs that have Filter = 1 in their minimum date, and this date has to be <= to the date made with my selections in the lists box makedate(Year,Month,1)).


In this case if I select year 2017 and month Feb I get 0 I guess due to the selections, I would like to retrieve 1 (the RowID=1)


I use the following formula:


=sum(aggr(
if(
date(min({<Year=, Month=>}Date))<= date(makedate(Year,Month,1)),
Count({<Year=, Month=,Filter={'1'}>} distinct  [ID])
)
,
RowID,[ID]))


Due to my real scenario I can’t do that through Year and Month as data island or with Alternate States.

Thank you and best regards.

Sara

1 Solution

Accepted Solutions
sunny_talwar

May be like the attached

Have only updated the text boxes and not the tables...

View solution in original post

9 Replies
sunny_talwar

May be this

=Sum({<Year, Month>} Aggr(If(Min({<Year, Month>}Date) <= MakeDate(Year, Month,1), Count({<Year, Month, Filter = {'1'}>} DISTINCT [ID])), RowID, [ID]))

sunny_talwar

Alternatively, you can try this

Count({<Year, Month, Filter = {'1'}, RowID = {"=Min({<Year, Month>}Date) <= MakeDate(Year, Month,1)"}>} DISTINCT [ID])

sunny_talwar

Just tried it out and you might need this

=Count({<Year, Month, Filter = {'1'}, RowID = {"=Min({<Year, Month>}Date) <= Only(TOTAL MakeDate(Year, Month,1))"}>} DISTINCT [ID])

or this

=Sum({<Year, Month>} Aggr(If(Min({<Year, Month>}Date) <= Only(TOTAL MakeDate(Year, Month,1)), Count({<Year, Month, Filter = {'1'}>} DISTINCT [ID])), RowID, [ID]))

Anonymous
Not applicable
Author

Thank you It seems that it work:

=Count({<Year, Month, Filter = {'1'}, RowID = {"=Min({<Year, Month>}Date) <= Only(TOTAL MakeDate(Year, Month,1))"}>} DISTINCT [ID])

When I confirm I`ll close and mark as correct.

Best regards.

Anonymous
Not applicable
Author

Hi Sunny I was testing with more data and it seems that is doesnt work for example:

      

RowIDYearMonthDateFilterID
12017101/01/20171A
22017102/01/20170A
32017203/01/20170A
42017204/02/20171B
52017205/02/20170B
62017206/02/20171C
72017207/02/20170C
82017208/02/20170C
92017209/02/20171D
102017210/02/20170D
112017211/02/20170D
122017212/02/20170D
132017213/02/20170D
142017214/02/20170E
152017215/02/20170E
162017216/02/20170E
162017317/03/20171E

For example in this table if I selec month =3 and year =2017, I would like to evaluate the min date for each ID and if there is one as filter I would like to count it. In this case the desire result will be 4 RowID(1,4,6 and 9)

Thank you for your advice it is greatly appreciated!

sunny_talwar

Try this

=Count({<Year, Month, Filter = {'1'}, ID = {"=Min({<Year, Month, Filter = {'1'}>}Date) <= Only(TOTAL MakeDate(Year, Month,1))"}>} DISTINCT ID)

Anonymous
Not applicable
Author

Hi Sunny,

The problem with that is that I dont want to the min date with the filter =1, i would like to evaluate in the min date of each ID if the Filter is equal to 0. Imagine the oposita case i would like to evaluate in the max date:

    

RowIDYearMonthDateFilterID
12017101/01/20171A
22017102/01/20170A
32017203/01/20170A
42017204/02/20171B
52017205/02/20170B
62017206/02/20171C
72017207/02/20170C
82017208/02/20170C
92017209/02/20171D
102017210/02/20170D
112017211/02/20170D
122017212/02/20170D
132017213/02/20170D
142017214/02/20170E
152017215/02/20170E
162017216/02/20170E
162017317/03/20171E

In this case the result will be 0.

Thank you

sunny_talwar

May be like the attached

Have only updated the text boxes and not the tables...

Anonymous
Not applicable
Author

Thank you This is what i was looking for