Skip to main content

Creating new variables

It can get hard to see what’s happening in your script as you introduce more and more functions embedded in other functions, as we did in the last step. Now is a good time to introduce the Variables view, which, among other things, gives you a way of putting complex functional compositions out of sight.

  1. Click Variables in the left-hand navigation ribbon.

    CNF01 (new).png

    This is the Variables view, which lists all variables to the project. There is a variable corresponding to each column in your data table — the data source. These are created automatically when you upload your table data.

    You can edit the variables' names here, as well as change other properties. What you want to do now is create a new variable that contains the composite function we created during the previous part of the tutorial.

  2. Click Compose to return to the Compose view.

  3. Select the composite function by clicking once on the precision function call in the script. It will turn grey.

    CNF02 (new).png
  4. Copy the composite function (Ctrl + C), then click Variables to return to the Variables view.

  5. Click the + NEW VARIABLE button.

    The New Variable dialog opens. You’ll see a warning that there is no data source but we are going to fix that.

    CNF03 (new).png
  6. Click in the VARIABLE NAME field, delete NewVariable, and type CapitalPopPercent.

    Note

    Variable names can be up to 40 characters in length. For other restrictions, see Variable Names.

  7. Click in the VARIABLE TYPE field and select NUMERIC from the drop-down.

  8. Click in the SOURCE field and paste the function call you copied in Step 4. This should appear in the field as [[precision(div(product(CapitalPop2016,100),StatePop2016),1)]].

    CNF04 (new).png
  9. Click Done.

    Tip

    When you have complex composite functions in your script, it can be useful to define a variable for that computation. First, this helps to simplify your script. Second, if the composite function performs a calculation that you need to perform multiple times, you can use the variable rather than build the composite function again and again.

  10. Click Compose.

  11. Select the composite function by clicking once on the precision function call in the script. It will turn grey.

  12. Click Insert Variable and select the CapitalPopPercent variable that you just created.

    CNF05 (new).png

    You have now replaced the complex compound function with your new variable. Your script should now look like this:

    CNF06 (new).png
  13. Click the ATL View button. The underlying ATL should look like this:

    [[Jurisdiction]] has a land mass of [[StateLandArea]] square kilometers and a population in 2016 of [[StatePop2016]], up [[percentageChange(StatePop2016,StatePop2010,1)]]% from 2010's figure of [[StatePop2010]]. The capital city, [[Capital]], has a population of [[CapitalPop2016]], which is up [[percentageChange(CapitalPop2016,CapitalPop2010,1)]]% from 2010's count of [[CapitalPop2010]]. Today the capital is home to [[CapitalPopPercent]]% of the state's population.

  14. Click Preview. The output text for Row 1 should be:

    New South Wales has a land mass of 800,641 square kilometers and a population in 2016 of 7,618,200, up 5.2% from 2010's figure of 7,238,800. The capital city, Sydney, has a population of 4,526,479, which is up 8.2% from 2010's count of 4,183,471. Today the capital is home to 59.4% of the population.

    There are no changes to text output because the newly created variable performs exactly the same computation as the complex compound function that it replaced. You have, however, simplified your script content.

Next, you'll learn how to add conditional variation to your script.

Adding conditional variation