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

Occurrence Count of Items

I have a Excel data Sheet like This

WagonDateStatus
A01/01/2021In Travel
A02/01/2021Stopped
A03/01/2021Stopped
A04/01/2021Stopped
A05/01/2021In Travel
A06/01/2021Stopped
A07/01/2021Stopped
A08/01/2021In Travel
A09/01/2021Stopped
A10/01/2021In travel
A11/01/2021In travel

Now I want to calculate the number of occurrences of Stops which is (3) but not the count of Stops which is (6)

Thanks in advance

3 Replies
brunobertels
Master
Master

Hi 

Add in your script a flag : 

somethink like that :

 

if(match(Status,'Stopped'), if(Status<>previous(Status),1,0)) as count,

 

than in your app as mesure :

Sum( count)

 

see below example : 

[Table]:
[Table]:
load *,
if(match(Status,'Stopped'), if(Status<>previous(Status),1,0)) as count;
LOAD * INLINE
[
Wagon,Date,Status
A,01/01/2021,In Travel
A,02/01/2021,Stopped
A,03/01/2021,Stopped
A,04/01/2021,Stopped
A,05/01/2021,In Travel
A,06/01/2021,Stopped
A,07/01/2021,Stopped
A,08/01/2021,In Travel
A,09/01/2021,Stopped
A,10/01/2021,In travel
A,11/01/2021,In travel
](delimiter is ',');

brunobertels_0-1624348991150.png

 

 

HAMID_AKBARI
Contributor II
Contributor II
Author

Thanks

I didnt test you solution yet 

but there might be a B or C wagons between As

 

brunobertels
Master
Master

Hi 

then as mesure use aggr function 

 

agrr(sum(count),wagon) to group stopped occurence per wagon