Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using Variables in Expressions

Hi Everybody;

as i'm new to QS i'm trying to figure our how variables are used in QS Expressions;

i have successfully created a Variable in the script called "NCDuration"

i tried to create a measure based on this variable in the following manner without success:

Count({$<[NCDuration>30]>}  ReportNumber)

The idea was to count all the existing records >30 days

will highly appreciate any help

3 Replies
JonnyPoole
Employee
Employee

Can you post the script command that sets the variable ? 

In SET ANALYSIS , a modifier always references an actual field in the data model like:

Count( {$<DurationField={">30"}>}   ReportNumber)

so if variable = 30 you can pull that in like:

Count( {$<DurationField={">$(NCDuration)"}>}   ReportNumber)

If NCDuration calculates something like Sum(DurationField) then you can reference another field like

Count {$<County={"$(NCDuration)>30"}>}  ReportNumber

...which would bring back a selection of countries where sum(Duration) by country was > 30 ... and from that selection get you a count of the ReportNumbers

ps:   you may want to do a count(distinct   to only get unique reportnumbers

Anyways post your script command and it may give clues

Not applicable
Author

Hi Jonathan and thank you for your prompt answer;

i have added the following line after the LOAD script

CloaseDate and CreateDate are dates represented as numbers in my file (extracted from a system we have)

i have checked that the NCDuration set the desired output and it works fine

SET NCDuration=Date(CloseDate,'DD/MM/YY')-Date(CreateDate,'DD/MM/YY')

i will look more closely at your answer to see if i've figure it out

Haim

JonnyPoole
Employee
Employee

Hi Haim,

I took the liberty of making this work internally. 

The working syntax in the measure is as follows.

count(  {$<ReportNumber={"=($(NCDuration)) < 30"}>}   ReportNumber)