How to calculate a variable with the formula editor

The calculate variable step is an all-purpose formula parser to create new variables in a more "Excelish" way. There are dozens of operators, comparisons, and functions that allow endless combinations. For a comprehensive list of functions and operands see here

Video Tutorial (Spanish)

First step. Writing a basic formula

The first step is to create a pipeline (click on "Create new --> Pipeline" on the top right) and select a data source, followed by "add step below --> Calculate Variable"

There are a couple of rules to creating new variables

  • Select a name on the textbox. If you select a variable name that already exists it will be overwritten
  • You can use @ to select variables of the dataset. Start writing the name of the variables and options will show up
  • You can do basic arithmetic operations such as (+, -, *, /, ^): @column1 + 3
  • You can use functions by typing the name followed by parenthesis and commas to separate parameters: round(@column) + @column2. Full list of functions is here: here.
  • The formula will always return the same number of rows as the original datasets, even if it involves calculations that usually reduce the dimensionality such as "Total sum per group". Check group and rolling windows functions below.
@Close + @Volume * 2)


Row Functions

Row functions are those that are calculated using only information from a single row in the dataset. That is, no values from other periods or entities are used in the calculation. This includes functions such as power, exp, sqrt, log, abs, trunc, round,sin, cos, etc.

log(@Close)+ sqrt(@Volume))

Nested calculations

Calculations can be nested inside other calculations to be used as parameters


Group Functions

Group functions are used to make calculations for subgroups within the dataset. The data is split by the unique values of the entities defined in the parameters and calculations are done for each separate group. Entities can be the real entities of the dataset or any other variable or even the result of nested calculations.

There are dozens of group functions. See a comprehensive list here

Example: Calculate for each ticker the cumulative price change vs the first price 
@Close / first(@Close, @Ticker)

Example: Calculate the cumulative sales per salesperson
cumsum(@sales, @salesperson)

Example: Calculate for each date the share of sales explained by each product vs the total sales of that date
@sales / sum(@sales, @date)

Rolling Window Functions

Rolling windows are a special class of group function where calculations are made within a group AND within a rolling window. The user has to define the number of periods to be included in the rolling calculation

Example: calculate the 20 day moving average for each ticker
rollingmean(@Close, 20, @Ticker)

Date and time Functions

Date and time functions are performed over DateTime variables (usually the @Date entity of the dataset) and include functions such as year, month or day, week, dao_of_year and more

Example: Extract the year from the date entity

Luciano Cohan

Written by

Luciano Cohan

Co-Fundador de Alphacast. Ex Subsecretario de Programación Macroeconómica. Data Science. Creando una plataforma para el trabajo colaborativo en economías

Related insights

  •

    How to integrate Alphacast with Excel for Mac?

    You will need the complete URL for the dataset that you want to integrate, which you can find by clicking the Download button and then copying (not downloading!) the URL attached to a TSV file.


  • Read more... alphacast_logo_1.png

    8 amazing econdashboards you cannot miss!

    Stop spending your day copying & pasting data from sources that frequently change their formats, and get your charts updated right away.

    Dashboards are updated every day with the most recent data. Remember that you can copy and clone everything you see on those dashboards. Create your charts or pipelines to transform

  •

    How can I create a basic dashboard?

    Here you will find some examples that will be useful when building your own dashboard

    Saving charts on your clipboard

    Before you start creating your first dashboard, it's useful you preselect the charts that you want to work with using the clipboard. The clipboard allows you to have all the charts

  •

    A short guide to Argentina's Mutual Funds Industry Analysis

    In this short tutorial, we will guide you on calculating ranks of YTD Total Returns for different funds and management companies.

    Alphacast hosts a number of daily updated datasets of Argentinas Mutual Funds Industry. Two weeks ago we began publishing detailed datasets for based on CAFCI daily reports, mostly in

  •

    A short guide to Argentina's Financial and Monetary Data

    There are more than 2.000 datasets in Alphacast, and there are plenty of hidden gems. This is a short "Must see" guide for those interested in Argentina's financial and monetary data.

    **Would you like to know more?