Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Quy_Nguyen
Specialist
Specialist

Creating quarter hour table

Hi everyone,

I am creating a quarter hour table by this script:

 

TimeDimension:
  Load
  Num(rowno()-1, '00') as TimeKey,
  Time(Floor((rowno()-1)/96, 1/24), 'hh:mm') as Hour,
  Time(Floor((rowno()-1)/96, 1/48), 'hh:mm') as HalfHour,
  Time((rowno()-1)/96, 'hh:mm') as QuarterHour
AutoGenerate 96;

 

It looks okay to me. But the result is a little bit weird as this:

clipboard_image_0.png

For each hour, I will have 4 quarter hour. But with the TimeKey 28, I got the quarter hour is 7:00, its hour and half hour are not correct.

clipboard_image_1.png

If I change the code by adding a magic number like this, I got the correct result:

 

TimeDimension:
Load
  Num(rowno()-1, '00') as TimeKey,
  Time(Floor((rowno()-0.9)/96, 1/24), 'hh:mm') as Hour,
  Time(Floor((rowno()-0.9)/96, 1/48), 'hh:mm') as HalfHour,
  Time((rowno()-1)/96, 'hh:mm') as QuarterHour
AutoGenerate 96;

 

 

Can anyone help me to explain what's wrong with the first script?

 

1 Solution

Accepted Solutions
sunny_talwar

2 Replies
sunny_talwar

This has to do with Rounding Errors

Quy_Nguyen
Specialist
Specialist
Author

Thank you Sunny!