Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
hermanitor
Contributor III
Contributor III

Qlik Sense Loop With Conditions

Hi there.

I have a table that looks like this...and I want to do a few things here....
Firstly I want to identify the minimum and maximum date where an F appears.

Then I then also want to count the number of consecutive F shifts...and just for an extras twist where there is an '/' this is defined as not working.  In other words ID 1 has worked 4 consecutive F shifts.  ID 2 has only worked 2 as the ES shift is a different shift type....
Does this make sense?

ID Date Shift
1 01/10/21 F
1 02/10/21 F
1

03/10/21

/
1 04/10/21 F
1 05/10/21 F
2 01/10/21 F
2 02/10/21 ES
2 03/10/21 F
2 04/10/21 F

 

Labels (1)
2 Replies
deepanshuSh
Creator III
Creator III

Maybe it could work like this, you need to create different if and else condition for getting the final output. 

for first min and max use the following condition;

if(Shift ='F', Max(Date)) as MaxDate If (SHift = 'F', Min (Date)) as  minDate 

or 

 

Load 

shift ,

Max (Date) as MaxDate,

Min(Date) as MinDate

Resident Table 

Group by Shift;

 

This way you can get max date for each shift. 

 

For second, are you ignoring the / and considering the shift as continuous or not?

Trial and error is the key to get unexpected results.
hermanitor
Contributor III
Contributor III
Author

Hi Deepan....
Just some feedback.  Tried the first solution, didn't like this.
Have amended the second solution...
Became
TableName:
Load
ID
ShiftCode

Max (Date) as MaxDate,

Min(Date) as MinDate
Resident Table

Where Shfitcode ='F'
Group by ID, ShiftCode;
This gives me the min and max dates where the shift is 'F' for all ID's.  Will try and work out first solution in a minute.
Would like to ignore when you have a symbol.  So just ignore the shift totally is where I want to be.
So Id No 1 would be 4 and Id no2 would be 2.
Does that explain it?