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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if else logic at script level

I want to compute if else logic at script level based on user selection. is it possible ?

I know it is very mush possible to do by writing if else expression on QV report. Howerver i want to push the expresion to script level. How do i do that ?

Example: A user wants to toggle between filed A and B on the fly by clicking on radio buttion (Flag). So the formula would be something like if (flag=1,A,B). However i want to write the formula at the script level not in the report. How do i do that ?

3 Replies
prieper
Master II
Master II

You may hand the values from a listbox into a variable. In the script you can reference to this variable and thus run different loops or different conditions.

HTH
Peter

Anonymous
Not applicable
Author

If I got your idea then you can use at least 2 variables - one for radio button value (0 or 1) and another for showing write field.

so in script it will be If '$(flag)'='1' Then SET variable2='A' Else SET variable2='B';

Then in analytic (QV report) you can use the variable2 for showing field user choosed, e.g. If('$(variable2)'='A',[Field A],[Field B])

Rgds,
Artjoms

Not applicable
Author

I am still struggling to find the correct solution to my problem. Here is how my code looks like. Basically what I am trying to do is to allow user to select lag 0,1,2,3 and display data accordingly as per the selection.

The issue here is; due to inner join (Load * inline function) on table "Drop"; record count blows up from 350K to around 1500K, resulting into virtual memory error. How do I avoid increasing record count? Is there a way to create variable at script level and allow users to select that variable at QV UI and remove existing load inline function?

DROP:

Load

KEY5 AS KEY,

SUM(ACT5) AS ACT1,

SUM(DP2) AS DP2,

SUM(DP3) AS DP3,

SUM(DP1) AS DP1,

SUM(DP0) AS DP0,

SUM(SP2) AS SP2,

SUM(SP3) AS SP3,

SUM(SP1) AS SP1,

SUM(SP0) AS SP0,

SUM(if(SDATE >= MONTHSTART(TODAY(),-12),BLAG0)) as "B0",

SUM(if(SDATE >= MONTHSTART(TODAY(),-12),BLAG1)) as "B1",

SUM(if(SDATE >= MONTHSTART(TODAY(),-12),BLAG2)) as "B2",

SUM(if(SDATE >= MONTHSTART(TODAY(),-12),BLAG3)) as "B3"

RESIDENT INI4

GROUP BY KEY5 ;

INNER JOIN (DROP)

LOAD * INLINE [

LAG

0

1

2

3]

;

LAGS:

LOAD

KEY AS KEY1,

LAG,

SUM(ACT1) AS ACT1,

SUM(IF(LAG=0,DP0,IF(LAG=1,DP1,IF(LAG=2,DP2,IF(LAG=3,DP3))))) AS DP,

SUM(IF(LAG=0,SP0,IF(LAG=1,SP1,IF(LAG=2,SP2,IF(LAG=3,SP3))))) AS SP,

SUM(IF(LAG=0,B0,IF(LAG=1,B1,IF(LAG=2,B2,IF(LAG=3,B3))))) AS BLAG

RESIDENT DROP

GROUP BY KEY,LAG;

DROP TABLE DROP;