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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Unable to evaluate interval field in IF statement

Hi,

I hope that somebody could help me solve the following problem please.

I have created a QlikView variable that evaluates an expression in order to extract the hour from a date field - having got the hour, if it is less that 7 then return 'AM', otherwise return 'PM' (the final calculation is a bit more involved than this but this demonstrates the problem).

NOTE: in the variable expression below, the field EventDate is a date time, for example, 21-Jun-2011 06:59:59.

The following variable expression correctly returns the hour element from the timestamp as a string (E.g. 21-Jun-2011 06:59:59 returns '06'):


=interval
(frac
  (timestamp
   (
    timestamp# (EventDate, 'DD-MMM-YYYY hh:mm:ss'),
    'DD/MM/YYYY hh:mm:ss'
   )
  ), 'hh'
)

However, when I add an if statement, the expression always evaluates true whatever the hour number (i.e. returns 'AM'):


=if( (interval
(frac
  (timestamp
   (
    timestamp# (EventDate, 'DD-MMM-YYYY hh:mm:ss'),
    'DD/MM/YYYY hh:mm:ss'
   )
  ), 'hh'
)
     ) < '07', 'AM', 'PM')

It seems that the problem would be solved if I convert the interval hour value to an integer but am not sure how to do this.

I have attached the QlikView document that demonstrates the problem.

Many thanks.

3 Replies
Not applicable
Author

Hi,

Try:

=if( num(interval

(frac

  (timestamp

   (

    timestamp# (EventDate, 'DD-MMM-YYYY hh:mm:ss'),

    'DD/MM/YYYY hh:mm:ss'

   )

  ), 'hh'

)

     ) < 7, 'AM', 'PM')

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

   Have a look at the example.

   I tried to achieve in different manner.

   Hope this will help you.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hi,

You are using single quate '7'. Instead use only 7, as you are comparing numeric value.