Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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.
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
Here is a screenshot from Qlik Sense 🙂
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:
Thanks!
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!