Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
qliklearnervir
New Contributor III

want to create conditional statement in where condition in script

Hi,

I am loading one table where i want to provide a condition that :

(1)  IF User select Type = Booking   than booking filter should add with where condition

(2) If user select Type = Arrival than arrival filter should Add with where condition

Type is a field having 2 values ' Booking' and 'Arrival'

variables are given below:

vBooking =([Booking Year] >= $(vBookingFromYear) and [Booking Year] <= $(vBookingToYear));

vArrival = Date([Arrival Date],'DD/MM/YYYY') >= Date(Addmonths(Today(),-4),'DD/MM/YYYY') and Date([Arrival Date],'DD/MM/YYYY') <= Date(Today(),'DD/MM/YYYY') ;

Script is given below:

booking_f:

LOAD [Booking WID],

            [Person WID]

      

FROM

$(vQvdFileLocation)booking_f.qvd

(qvd)

//WHERE([Booking Year] >= $(vBookingFromYear) and [Booking Year] <= $(vBookingToYear))

//and Date([Arrival Date],'DD/MM/YYYY') >= Date(Addmonths(Today(),-4),'DD/MM/YYYY') and Date([Arrival Date],'DD/MM/YYYY') <= Date(Today(),'DD/MM/YYYY')   ;

where

Pick( Match ( Type, 'Booking', 'Arrival')

,'$(vBooking)','$(vArrival)');

Please suggest ................the possible solution

2 Replies

Re: want to create conditional statement in where condition in script

Hi,

Create a variable like vType and definition as =GetFieldSelections(Type). So when the user selects "Booking" or "Arrival", it will be stored in the variable. Then you can use the variable in the script.

booking_f:

LOAD [Booking WID],

            [Person WID]

     

FROM

$(vQvdFileLocation)booking_f.qvd

(qvd)

where

Pick( Match ( '$(vType)', 'Booking', 'Arrival')

,'$(vBooking)','$(vArrival)');


Edit: Create the variable in front end. See the screenshot.


Capture.PNG

After select the listbox, you can use the script to reload the data.

Re: want to create conditional statement in where condition in script

I think you need this selection during loading, you can do this with input fields (look in the help) but I do not suggest this way, It should be better to load everithing then filter the result through a variable.

let me know

Community Browser