Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
morenoju
Partner - Specialist
Partner - Specialist

Field not updating after automatic load

Hi guys,

I have the following piece of code in my load script:

[hotspots_currentperiod]:
LOAD
if (hour(now())>='6' AND hour(now())<'10',1,if (hour(now())>='16' AND hour(now())<'19',2,0)) As CurrentPeriod
INLINE [
CurrentPeriod
];

Basically, I want to divide the day in three periods:

- Between 6 and 10 AM it is period 1

- Between 4 PM and 7 PM period 2

- Rest: period 0

This was working OK until I published the app. It is right now 7:25 PM, and I'm reloading data every 5 minutes. CurrentPeriod=2 no matter what. 

Do you see anything wrong in my code?

Thanks

Labels (3)
17 Replies
morenoju
Partner - Specialist
Partner - Specialist
Author

Same result, the field does not update (still = 2).
I think the original expression was OK. If I put it in a sheet of the app, in a text component, the result for now (9:28 AM) is '1', which is correct.
if (hour(now())>='6' AND hour(now())<'10',1,if (hour(now())>='16' AND hour(now())<'19',2,0))
sunny_talwar

I guess what I am trying to understand is the value of Hour(Now()) or Time(Frac(Now())) when the if statement is getting evaluated...

for example... I ran this script

[hotspots_currentperiod]:
LOAD Now() as CurrentDateTime,
	 Time(Frac(Now())) as CurrentTime,
	 If(Frac(Now()) >= MakeTime(6) and Frac(Now()) < MakeTime(10), 1,
	 If(Frac(Now()) >= MakeTime(16) and Frac(Now()) < MakeTime(19), 2, 0)) as CurrentPeriod_Time,
	 Hour(Now()) as CurrentHour,
	 If(Hour(Now()) >= 6 and Hour(Now()) < 10, 1,
	 If(Hour(Now()) >= 16 and Hour(Now()) < 19, 2, 0)) as CurrentPeriod_Hour
AutoGenerate 1;

and I am seeing this

image.png

I am seeing that CurrentTime is 9:31:40 AM and Current Hour is 9... so it make sense that I am getting 1... what do you get when you run the above script? Share a screenshot similar to what I posted using the above script.

morenoju
Partner - Specialist
Partner - Specialist
Author

Hi @sunny_talwar,

Isn't that Qlikview? I'm using Qlik Sense 3.2.

Anyway, I'm going to be using the following workaround: In every sheet of my app where I need CurrentPeriod, I'm going to paste:

if (hour(now())>='6' AND hour(now())<'10',1,if (hour(now())>='16' AND hour(now())<'19',2,0))

The expressions will get longer, but at least I'm sure that I get 1,2 and 0 at the correct times of the day.

Thanks for all the input though!

Juan

sunny_talwar

Well does it make a difference if I use QlikView or Qlik Sense. The script should return the same value. I guess you are not up for testing any longer, but one thing to note here is the Now() function will be continuously running and might slow down. but if you have a small application... it should not be a big deal.
sunny_talwar

Here is a screenshot from Qlik Sense 🙂

image.png

morenoju
Partner - Specialist
Partner - Specialist
Author

Hi @sunny_talwar, yes I can test further, no problem!

In fact, I've tried your piece of code, and yes, it brings the correct value for CurrentPeriod:

image.png

Thanks!

sunny_talwar

So, this seems to be working here right.. both CurrentPeriod_Time and CurrentPeriod_Hour seems to give 0 which is what you would expect to see based on your if statement?
morenoju
Partner - Specialist
Partner - Specialist
Author

Yes, it does! I wonder what was the issue when using Now() without Frac() and MakeTime(), and why the load script gives different results than the same expression in a text box in the sheet.

But in any case your alternative definitely works. Thank you!