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

Times

Hi, what do i miss here??

if(frac(STARTTIME)>=MakeTime(6,45) and frac(STARTTIME)<=MakeTime(15,29,59),'FM',
if(frac(STARTTIME)>=MakeTime(15,30) and frac(STARTTIME)<=MakeTime(22,59,59),'EM','Natt')) as Shift

JohnSSI_0-1713197425254.png

JohnSSI_1-1713197531018.pngJohnSSI_2-1713197626578.png

 

 

Labels (1)
6 Replies
BrunPierre
Partner - Master
Partner - Master

Hi, perhaps

If(Frac(STARTTIME) >= MakeTime(6,45) and Frac(STARTTIME) <= MakeTime(15,29,59), 'FM',
If(Frac(STARTTIME) >= MakeTime(15,30) and Frac(STARTTIME) <= MakeTime(22,59,59), 'EM',
'Natt')) as Shift

John-SSI
Contributor III
Contributor III
Author

Hi, got the same result!

marcus_sommer

Time values are as a part of 1 no integer. Because of the fact that Qlik doesn't used a decimal number-system else a binary ones it's not possible to produce exact values. Therefore a comparing against = or <= >= may result in a wrong matching.

A workaround for such scenarios would be to round both sides of the comparing identically, maybe like:

floor(Frac(STARTTIME), 1/24/60/60) >= floor(MakeTime(6,45), 1/24/60/60)

John-SSI
Contributor III
Contributor III
Author

Interesting, but i do something wrong here?
(I just tested the FM)
If(Floor(Frac(STARTTIME),1/24/60/60) >= Floor(MakeTime(6,45) and Floor(Frac(STARTTIME),1/24/60/60) <= Floor(MakeTime(15,29,59), 1/24/60/60)), 'FM',
If(Frac(STARTTIME) >= MakeTime(15,30) and Frac(STARTTIME) <= MakeTime(22,59,59), 'EM',
'Natt')) as Shift

marcus_sommer

Yes it's not quite correct because the floor(VALUE, 1/24/60/60) needs to be exactly applied to each part of each comparing. Especially skipping it here: Floor(MakeTime(6,45)) means that's not rounded to a second else to an integer and here ZERO.

Before applying such comparing in an if-loop it would be useful to return all essential parts within own fields / expressions, like

num(MakeTime(6,45), '#.00000000000000')
num(floor(MakeTime(6,45), 1/24/60/60), '#.00000000000000')
time(Frac(STARTTIME))
num(floor(frac(STARTTIME), 1/24/60/60), '#.00000000000000')
...

to see all results directly which is also mostly a direct hint why a condition-expression returned an unexpected result.

John-SSI
Contributor III
Contributor III
Author

Hi all, i fixed this. Reading database values and ETL --> QVD. So the time of and timestamp get's corrected 🙂
Thanx all for your help.