Qlik Community

Ask a Question

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
Qlik Users, make your voice heard! Participate in Wisdom of Crowds® Market Study: Start Survey
cancel
Showing results for 
Search instead for 
Did you mean: 
nougatitati
Contributor III
Contributor III

Autogenerate while loop with hourly increment

I'm trying to generate hour-by-hour timestamps for each hour between two dates.

To do this, I take a functional script for doing the equivalent problem, which instead of hour-by-hour, it generates a timestamp for each day between the two specified dates.

autogen0.JPG

This results, as expected, with this:

autogen1.JPG

I attempt to amend this script to have an addition of hours rather than days:

autogen2.JPG

However this results in an unusually long load time, that never seems to end:

autogen3.JPG

Since it is a while loop, the terminating condition would be a candidate for the problem. However making test variables and checking the result of adding hours does indicate this process does work in isolation:

autogen4.JPG

Results in:

autogen5.JPG

As expected.

Why is the addition failing in the while loop, causing it to never terminate?

1 Solution

Accepted Solutions
nougatitati
Contributor III
Contributor III

I figured it out, and I'm posting the solution here just incase somebody finds it relevant to their work.

The problem is that I was adding a "Time#(IterNo() - 1, 'h')", which indeed increments the hour, for some reason it is not designed to be able to add to a given day to progress to the following day. To illustrate:

  • 29/08/19 22:00 + Time#(1, 'h') evaluates to 29/08/19 23:00, however
  • 29/08/19 23:00 + Time#(1, 'h') evaluates to 29/08/19 00:00

The way to remedy this is to perform the addition using the interval function instead. This will elicit the required results:

  • 29/08/19 22:00 + Interval#(1, 'h') evaluates to 29/08/19 23:00, and as required,
  • 29/08/19 23:00 + Interval#(1, 'h') evaluates to 30/08/19 00:00

When the 'interval' function is placed in the while condition, the loop will terminate as required.

clipboard_image_0.png

View solution in original post

1 Reply
nougatitati
Contributor III
Contributor III

I figured it out, and I'm posting the solution here just incase somebody finds it relevant to their work.

The problem is that I was adding a "Time#(IterNo() - 1, 'h')", which indeed increments the hour, for some reason it is not designed to be able to add to a given day to progress to the following day. To illustrate:

  • 29/08/19 22:00 + Time#(1, 'h') evaluates to 29/08/19 23:00, however
  • 29/08/19 23:00 + Time#(1, 'h') evaluates to 29/08/19 00:00

The way to remedy this is to perform the addition using the interval function instead. This will elicit the required results:

  • 29/08/19 22:00 + Interval#(1, 'h') evaluates to 29/08/19 23:00, and as required,
  • 29/08/19 23:00 + Interval#(1, 'h') evaluates to 30/08/19 00:00

When the 'interval' function is placed in the while condition, the loop will terminate as required.

clipboard_image_0.png

View solution in original post