Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
GLG
Partner - Contributor
Partner - Contributor

Counting events between monday 5pm to friday 8:00am

Hi everyone,

I would like to count the number of events that occur between let say monday 5:00pm to friday 8:00am. I don't know how to proceed. 

I have the following list:

Event - day of the week - hour of event 

1 - Monday - 04:00:01

1 - Tuesday - 19:34:00

0  - Wednesday- 02:10:00

etc..

Could you help me writing the expression ( Sum({$<expression ?? >} Event) ) to compute this data?

 

 

2 Replies
johngouws
Partner - Specialist
Partner - Specialist

Morning. I needed to do something similar to this a few months back. It turned out to be a mission and actually easier to do the 'preparation' in the script with a preceding load. I had great help from @sunny_talwar . 
To start off, you have to have a timestamp field in your data for this to work. Hopefully you can modify this to work for you. Needed this field and variable. 

START_TIME = Date([DateTime],'YYYY-MM-DD hh:mm:ss') as START_TIME,
vDayStart  = LET vDayStart = 04; //04 hour in the morning//
vDayEnd = LET vDayEnd = 20; // 20 hour in the evening//
vMinute = LET vMinute = 00; 
WeekDayNo in my case I thing Friday was 4. You will have to check yours. 

LOAD
*,
/**/
if(WeekDayNo <=4 and frac(START_TIME) >= maketime($(vDayStart),$(vMinute))and frac(START_TIME) < maketime($(vDayEnd),$(vMinute)),1,0 ) as [Normal Hours],

If((WeekDayNo=0 and frac(START_TIME)> maketime($(vDayEnd),$(vMinute))) or (WeekDayNo=4 and frac(START_TIME)<= maketime($(vDayStart),$(vMinute)))
or (WeekDayNo>0 and WeekDayNo<4 and (frac(START_TIME) <= maketime($(vDayStart),$(vMinute)) or frac(START_TIME) > maketime($(vDayEnd),$(vMinute)))),1,0 ) as [After Hours],

If((WeekDayNo=0 and frac(START_TIME)<= maketime($(vDayStart),$(vMinute))) or (WeekDayNo=4 and frac(START_TIME)> maketime($(vDayEnd),$(vMinute))) or (Match(WeekDayNo,5,6)),1,0) as Weekends
/**/
;
LOAD
......
.....
;

 

GLG
Partner - Contributor
Partner - Contributor
Author

Thanks a lot ! I will try to test that and let you know !