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: 
Not applicable

pivot table: aggregated count dependending of If(date=max(date)) condition

Hello,

I have this sort of values:

CountryRegionCityIDDate

Product

Client

C1R1C1105/10/2011P1C1
C2R2C2102/10/2011P4C4
C3R3C3305/02/2011P6C3
C4R4C4410/02/2011P7C2

I want to have in a pivot table with dimension Country,Region,City this value:

Aggr(

     Count( distinct

               If( Date=Max(Date) and Product=P2 and ..., ID)

     )

     ,Country,Region,Status,ID

)

this sort of expression only give me "0" or "-".

I guess the condition Date=Max(Date) don't work. I want only count the ID if it has reach is maximum date on one or more data lines which validate also the other "IF" condition, aggregated by the dimensions of the pivot table.

I can't send you my application.

Could you help me?

6 Replies
tanelry
Partner - Creator II
Partner - Creator II

Maybe create a variable vMaxDate (=Max(Date) ) and use this in the expression.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Is there any particular reason you need an aggr expression here? If you use this in a table with the same dimensions as the aggregate, I dont think it will do anything useful.

I would try

     Count({<Date = {'$(=Date(Max(Date)))'}, Product = {'P2'}>} ID)

If you have other conditions, add them in the same form as the Product condition.

(Assumes the field Date is in the default date format for your system)

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Hi,

The reason to use the aggregate is the max(date) is for each ID.

For example, if I have the data below.

ID,Date

1,06/12/2000

1,NULL

1,15/02/2001

2,03/04/1997

3,06/10/2011

3,06/07/2012

I will only take this lines:

1,15/02/2001

2,03/04/1997

3,06/07/2012

I want to have in my pivot the count of distinct ID by the Country,Region and Status only when the Date value is the max for the ID in order to take only the most recent status fo each ID (Date by ID, not the Total Date over all ID).

tanelry
Partner - Creator II
Partner - Creator II

Then you need to aggregate over max date before counting:

Count( distinct

               If( Date=Aggr(Max(Date),Country,Region,Status,ID) and Product=P2 and ..., ID)

)

Hope this helps.

Not applicable
Author

Thanks.

But how the ID at the aggregate condition level is matched to the ID in the count function?

My pivot don't use ID in the dimension, that's why I have done this aggregate by Country,Region,Status,ID.

Not applicable
Author

Hello,

I haven't found a solution, so I solved it without use expression.

I have used a flag column in database with a "True" flag when I reach my max date for a group Country,Region,Status.

Regards.