Using variables in expressions

Variables can be used anywhere, including in expressions. Variables can hold an entire expression, but they can also contain parts of it.

To use a variable that contains part of an expression, simply use the dollar-sign expansion within the expression. Say you had the following variable created in the script:

LET vCurrentYear = year(today());
SET vMySalesField = '[Sales]';

You could create a chart that calculates sales for the current year using the variable vCurrentYear:

sum(if([Year] = $(vCurrentYear), $(vMySalesField))

This expression returns the sales for the current year.

Using an IF statement inside the aggregation will make the aggregation work only when the condition within the IF statement is true.

Variables can also contain the whole expression, which makes it very easy to maintain if the same expression is used in different charts within an application. The following script code shows an example:

SET vExpression = count(distinct [Customers]);

After a script reload, the vExpression variable will hold the expression as a string that can be directly used in any chart expression as follows:

$(vExpression)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.177.125