Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
John-SSI
Contributor III
Contributor III

Shift workdays and Weekends

Hi, i have this code in script during the weekdays (Mon-Fri) 3 shifts
But on saturday and sunday we only have 2 shift.

Can i manipulate this in a way?

Weekdays (Mon-Fri) 3 shift

if(time(frac(ScheduledAt))>=('06:00:00') and time(frac(ScheduledAt))<=('13:59:59'),'Day',
if(time(frac(ScheduledAt))>=('14:00:00') and time(frac(ScheduledAt))<=('21:59:59'),'Evning','Night')) as WoShift

Saturday we only have 2 shifts

06:00 to 17:59 and 18:00 to 05:59
Is there possibility to get in the same in above?

Labels (2)
1 Solution

Accepted Solutions
cwolf
Creator III
Creator III

More simpler and clearer:

MAP_WORKDAYS:
Mapping
load
Hour,
if(Hour>=6 and Hour<14,'Day',if(Hour>=14 and Hour<22,'Evening','Night')) as Shift;
load
RecNo()-1 as Hour
AutoGenerate 24;

MAP_WEEKEND:
Mapping
load
Hour,
if(Hour>=6 and Hour<18,'Day','Night') as Shift;
load
RecNo()-1 as Hour
AutoGenerate 24;


T:
load
*,
if(WeekDay(ScheduledAt)<5,ApplyMap('MAP_WORKDAYS',Hour(ScheduledAt)),ApplyMap('MAP_WEEKEND',Hour(ScheduledAt))) as Shift
From ...

View solution in original post

3 Replies
lennart_mo
Creator
Creator

Hi @John-SSI,

Try using the Weekday()-Function, it returns a value from 0 to 6, 0 being monday.

So you could create additional cases for saturday and sunday via if-statements, depending on weekday(ScheduledAt).

Hope this helps!

cwolf
Creator III
Creator III

More simpler and clearer:

MAP_WORKDAYS:
Mapping
load
Hour,
if(Hour>=6 and Hour<14,'Day',if(Hour>=14 and Hour<22,'Evening','Night')) as Shift;
load
RecNo()-1 as Hour
AutoGenerate 24;

MAP_WEEKEND:
Mapping
load
Hour,
if(Hour>=6 and Hour<18,'Day','Night') as Shift;
load
RecNo()-1 as Hour
AutoGenerate 24;


T:
load
*,
if(WeekDay(ScheduledAt)<5,ApplyMap('MAP_WORKDAYS',Hour(ScheduledAt)),ApplyMap('MAP_WEEKEND',Hour(ScheduledAt))) as Shift
From ...
John-SSI
Contributor III
Contributor III
Author

Works like a charm 🙂