Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
garry107
Contributor
Contributor

Count of Max date

Hi,

Can't figure out this simple problem:

DATES:
LOAD id, Date#(date) as date, status INLINE [
id, date, Area
A, 01/01/2018, 18

B, 02/02/2018, 25

B, 02/03/2018, 26
C, 03/03/2018, 31
D, 04/04/2018, 42

D,04/05/2018, 43    

D, 04/05/2018, 44];

I'm trying to create an expression to:

- count (Area) where Date = maxDate for eg: for id 'D' there are three dates, trying to get count when date is max which is 04/05/2018. Same for id B where date is maxdate which is 05/03/2018. where date in format of MM/DD/YYYY.

Would appreaciate the help.

-Garry

15 Replies
garry107
Contributor
Contributor
Author

what if the data is

DATES:
LOAD id, Date#(date) as date, status INLINE [
id, date, Area, State
A, 01/01/2018, 18, Open    

B, 02/02/2018, 25 ,Closed

B, 02/03/2018, 26, Open
C, 03/03/2018, 31 ,Closed
D, 04/04/2018, 42, Open

D,04/05/2018, 43   ,Closed

D, 04/05/2018, 44,, Open ];

same requirement with state = closed.

sunny_talwar

Same requirement? as in the first requirement?

garry107
Contributor
Contributor
Author

Yes same requirement.

Sum(Aggr(If(Max(TOTAL <id> date) = date, Sum(1), 0), id, date))


The above gives me for each ID what was the count of records with max(Date)


Requirement is to see the above with State is closed

sunny_talwar

Try this

Sum({<state = {'closed'}>} Aggr(If(Max({<state = {'closed'}>} TOTAL <id> date) = Only({<state = {'closed'}>} date), Sum({<state = {'closed'}>} 1), 0), id, date))

garry107
Contributor
Contributor
Author

This works.

Thanks a lot!!

garry107
Contributor
Contributor
Author

How to derive the max of above value as a Reference line?

RangeSum(

Sum(Aggr(If(Max(TOTAL <id> date) = date, Sum(1), 0), id, date))

-Above(Sum(Aggr(If(Max(TOTAL <id> date) = date, Sum(1), 0), id, date)))

)


for this?