Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
chrismtb
Creator
Creator

Time Conditional QVD save?

Hi All,

How do I create a QVD based on a time condition. I have a script that runs every 30 mins however I only want to update part of the output within certain time-frames.

I have an inline table with an example schedule:

Time_1, Time_2, Row_No

08:00, 09:45, 1

12:00, 13:45, 2

16:00, 17:45, 3

20:00, 21:45, 4

I only want my script to update the QVD if it runs between the times 1 and 2 as stated.

I have been using the Now() function elsewhere in the document (carefully) however I don't know how to link it as a basis for the store QVD.

Please help!!


1 Solution

Accepted Solutions
sunny_talwar

Here is a sample script you can use

Table:

LOAD Num(Time#(Time_1, 'hh:mm')) as Time_1,

Num(Time#(Time_2, 'hh:mm')) as Time_2,

Row_No;

LOAD * INLINE [

    Time_1, Time_2, Row_No

    08:00, 09:45, 1

    12:00, 13:45, 2

    16:00, 17:45, 3

    20:00, 21:45, 4

];


FOR i = 1 to FieldValueCount('Row_No')


LET vVar$(i)Start = FieldValue('Time_1', $(i));

LET vVar$(i)End = FieldValue('Time_2', $(i));

NEXT;


IF (Floor(Frac(Now()), 1/1440) > vVar1Start and Floor(Frac(Now()), 1/1440) < vVar1End) or (Floor(Frac(Now()), 1/1440) > vVar2Start and Floor(Frac(Now()), 1/1440) < vVar2End) or (Floor(Frac(Now()), 1/1440) > vVar3Start and Floor(Frac(Now()), 1/1440) < vVar3End) or (Floor(Frac(Now()), 1/1440) > vVar4Start and Floor(Frac(Now()), 1/1440) < vVar4End) THEN


STORE ...;


ENDIF;

View solution in original post

4 Replies
sunny_talwar

I guess create 8 variables and check Now() against all of them to see if it is between the two limits... if it is, then store... else nothing

IF (Now() > vVar1Start and Now() < vVar1End) or (Now() > vVar2Start and Now() < vVar2End) or (Now() > vVar3Start and Now() < vVar3End) or (Now() > vVar4Start and Now() < vVar4End) THEN

     STORE .....;

ENDIF;

chrismtb
Creator
Creator
Author

Thanks Sunny I will give it a go - 2 quick related questions:

1) Do i need to set the times for the variables when doing my variable deceleration at the start of the doc or can i feed them somehow from the inline table?

2) Do i need to do anything odd with regards to storing the times / comparing to Now() - past experience from the outside world has shown these things can act a bit odd if not considered in the correct format?

sunny_talwar

Here is a sample script you can use

Table:

LOAD Num(Time#(Time_1, 'hh:mm')) as Time_1,

Num(Time#(Time_2, 'hh:mm')) as Time_2,

Row_No;

LOAD * INLINE [

    Time_1, Time_2, Row_No

    08:00, 09:45, 1

    12:00, 13:45, 2

    16:00, 17:45, 3

    20:00, 21:45, 4

];


FOR i = 1 to FieldValueCount('Row_No')


LET vVar$(i)Start = FieldValue('Time_1', $(i));

LET vVar$(i)End = FieldValue('Time_2', $(i));

NEXT;


IF (Floor(Frac(Now()), 1/1440) > vVar1Start and Floor(Frac(Now()), 1/1440) < vVar1End) or (Floor(Frac(Now()), 1/1440) > vVar2Start and Floor(Frac(Now()), 1/1440) < vVar2End) or (Floor(Frac(Now()), 1/1440) > vVar3Start and Floor(Frac(Now()), 1/1440) < vVar3End) or (Floor(Frac(Now()), 1/1440) > vVar4Start and Floor(Frac(Now()), 1/1440) < vVar4End) THEN


STORE ...;


ENDIF;

chrismtb
Creator
Creator
Author

having run it through a couple of times, i can confirm it works like a charm.

Thanks again Sunny for getting to the bottom of this one!