Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ashis
Creator III
Creator III

Unable to define a variable in script level

Hi ,

When i define a variable from application settings -> variable overview and add variable name vVariable and define it as 

=date(max(If(if(Instance='XYZ',DATE) > Today()-4, '2000-01-01',if(Instance='XYZ'))),'YYYY-MM-DD')

It returns a date and it is right , but if i define the same variable from the script level as 

 

let vVariable 
=date(max(If(if(Instance='XYZ',DATE) > Today()-4, '2000-01-01',if(Instance='XYZ'))),'YYYY-MM-DD')

 

it through an error saying syntax error, unexpected token ',' expected nothing , and it shows error for this line.

I want to evaluate the value of the variable thus i put let command instead of set . Set does not through an error but pass a string. i want to evaluate the value.

Any idea why it is giving an error with the let statement in the script please.

 

Thank you,

Labels (1)
7 Replies
marcus_sommer

Try it in this way:

set vVariable 
= date(max(If(if(Instance='XYZ',DATE) > Today()-4, '2000-01-01',if(Instance='XYZ'))),'YYYY-MM-DD');

- Marcus

ashis
Creator III
Creator III
Author

Hi Marcus,

Thank you for your response. Actually i want to evaluate the value in hence suing Let instead of Set as i mentioned in my post.

I want to use the same variable in NPrinting that's the reason i need to do with Let otherwise it is taking as string with Set.

Thank you,

PradeepK
Creator II
Creator II

Not sure what is going on inside your if conditions..

But don't you think you need GROUP BY and LOAD statement to use Max() aggregate function in Script. 

 

I hope this helps!

marcus_sommer

Like PradeepK mentioned you will need a load-statement if you want to evaluate any data from tables. After that you could use functions like peek() or fieldvalue() to pick your wanted values from this table and to assign it to a variable.

In your case the efforts for this load seems quite heavy compared to the creation within the UI.

- Marcus 

ashis
Creator III
Creator III
Author

Thank you Pradeep for your suggestion. Will try that way.

ashis
Creator III
Creator III
Author

Hi Marcus,

Yes , i agree. I will try what Pradeep and you mentioned.

Thank you,

Cole_114
Contributor
Contributor


@FaceTime PC wrote:

Hi ,

When i define a variable from application settings -> variable overview and add variable name vVariable and define it as 

=date(max(If(if(Instance='XYZ',DATE) > Today()-4, '2000-01-01',if(Instance='XYZ'))),'YYYY-MM-DD')

It returns a date and it is right , but if i define the same variable from the script level as 

 

let vVariable 
=date(max(If(if(Instance='XYZ',DATE) > Today()-4, '2000-01-01',if(Instance='XYZ'))),'YYYY-MM-DD')

 

it through an error saying syntax error, unexpected token ',' expected nothing , and it shows error for this line.

I want to evaluate the value of the variable thus i put let command instead of set . Set does not through an error but pass a string. i want to evaluate the value.

Any idea why it is giving an error with the let statement in the script please.

 

Thank you ,


It appears to be that since my answer has been posted the naming show has gotten more formal. Individuals who instruct, compose books, and so forth talk about  Var affirmation, and capacity assertion.

Here is the extra Wikipedia post that underpins my point: Declarations and definitions .and to respond to the primary inquiry. Pronounce variable before your capacity.