38
496
Accessing Data and Data Analysis
Formulas, Local Variables and Functions
You could have simply created a formula to calculate the margin for each year.
The advantage of creating a variable is that you can then re-use it more easily in
other formulas. For example, you can now easily calculate the percent increase
in margin between the 2001 and 2002 using the variables you have just created
and display the increase in a new column in the table. The formula for the 2001-
2002 growth is as follows:
=FormatNumber((((<2002 Margin> - <2001 Margin>)/<2001 Margin>)
* 100) ,"0.0")&"%"
and the formula for 2002-2003 growth is:
=FormatNumber((((<2003 Margin> - <2002 Margin>)/<2002 Margin>)
* 100) ,"0.0")&"%"
EXAMPLE
Using function output as input to another function
You can use the output of a function as the input to another function. In this way
you can combine functions to create complex formulas. For example, the
UniverseName() function returns a string containing the name of a universe on
which a data provider is based. You use this function by supplying the the name
of the data provider as a string argument, for example:
UniverseName(‘Sales’).
The problem with hard-coding a data provider name in this way is that, if the data
provider name is changed, the function will no longer work.
You solve this by using the output of the DataProvider() function as input to the
UniverseName() function. DataProvider() takes a variable as input, so
DataProvider(<Sale Date>)
returns the name of the data provider of the Sale Date variable. As a result, the
formula
UniverseName(DataProvider(<Sale Date>))
always returns the universe name, even if the data provider name is changed.
EXAMPLE
Determining the first and last days of the previous month
It is commmon to run reports against the last complete month’s data. In order to
do this you need to determine the first and last days of the previous month. You
do this by creating variables that return these dates and then using these
variables in your report. These variables combine numerous functions and use
function output as the input to other functions.