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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help to Declare and Assign complicated variable just into the script

[View:http://community.qlik.com/cfs-file.ashx/__key/CommunityServer.Components.UserFiles/00.00.02.89.41/Test_2D00_Creating-Group-Sample-20100411000.qvw]

Hi guys,

I am declaring the variable "vSalesByCurrency" into Document properties as:

If($(vCountYear)>3, Sum($(=Concat(SalesByCurrency))) * $(vYearFlag), Sum($(=Concat(SalesByCurrency))))

and then using it as an expression in Table1 as:

=$(vSalesByCurrency)

The question is: Is there any chance to declare and assign this variable just in the script?

I want to avoid declaring it in Document properties.

I've been trying several ways, but getting internal error...

see the attachment.

Thanks in advance for any help,

Aldo.

7 Replies
vupen
Partner - Creator
Partner - Creator

Certainly, you can declare and assign values to a variable from within the script.

The syntax is:


Let vMyStartDate = MakeDate(2009,12,10);


Alternately, you can use Set instead of Let. You can see the help file for the differences.

Not applicable
Author

Hi man,

Thanks for answering.

I know how to declare a simple and assign a simple one, but getting hard with the example I post above...

Aldo.

vupen
Partner - Creator
Partner - Creator

The problem with the variable assignment in your example are 2:

a. You are using a set modifier - by using Sum($=<exp>). Set modifiers are not allowed inside the script

b. You are trying to sum a string; and then multiply a string with a number - Concat(SalesByCurrency) returns a string, and this is being summed up.

Not applicable
Author

Hi Upendra,

Could you help to understand what's the meaning of:

$( =Concat(SalesByCurrency) )

Thanks,

Aldo.

vupen
Partner - Creator
Partner - Creator

Concat is an aggregate function, and should be used with Group By.

Concat creates a string (a seperator can be specified) that is made up of values in successive rows.

And $(=<exp>) is a set modifier, where you are trying to calculate the sum, but with a different criterion (the formula you gave is incomplete).

Ex. Sum ({$<Currency=$(=$(vCurrency))> Sales} will give Sales for the current selection, but only for the defined Currency.

Not applicable
Author

Hi,

Instead of Dollar sign in script use this ' & Chr(36) & '

Not applicable
Author

Thanks guys,

I will try using your suggestions.

Once I have the answer to the post, I will set it to solve.

Thanks a lot,

Aldo.