Formulas

Formulas allow you to create calculated columns that automatically update when referenced data changes, ensuring your visualizations always reflect the latest calculations.

Overview

Formulas in Mappica enable you to create dynamic, calculated columns that derive their values from other columns in your dataset. When you enable a formula on a column, it becomes locked for manual editing and automatically recalculates whenever the referenced columns change. This ensures data consistency and eliminates the need for manual updates.

Formula columns can be used just like other dataset columns in components like charts, maps, tables, and filters. They support both numeric calculations and text manipulation.

Supported Field Types

Numeric Fields (Full Formula Support)

Formulas work with all numeric field types, providing full mathematical and logical operations:

  • Number: Standard numeric values
  • Percent: Percentage values
  • Currency: Monetary values with currency symbols
  • Measurement: Values with units (e.g., miles, kilometers, etc.)

Text Fields (Limited Formula Support)

Text formulas support string manipulation and conditional logic:

  • Text: Plain text fields
  • Ordinal: Text fields with predefined order values
  • Markdown: Rich text formatting

Formula Syntax

Field References

Reference other columns using the # symbol followed by the field name. When you type #, a dropdown will appear showing available fields you can reference:

#Revenue + #Costs
#First Name + " " + #Last Name

Mathematical Functions

Basic Arithmetic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • ^ Exponentiation
  • % Modulo

Advanced Mathematical Functions

Function
Syntax
Description
Example
MINMIN(value1, value2, ...)Returns smallest valueMIN(Federal, State, Local)
MAXMAX(value1, value2, ...)Returns largest valueMAX(Q1, Q2, Q3)
ABSABS(value)Returns absolute valueABS(Temperature)
ROUNDROUND(value, decimal_places)Rounds to specified decimalsROUND(Average Score, 2)
ROUNDROUND(value)Rounds to nearest integerROUND(Test Score)
FLOORFLOOR(value)Rounds down to integerFLOOR(Test Score)
CEILCEIL(value)Rounds up to integerCEIL(Rating)
SQRTSQRT(value)Square rootSQRT(Population Density)
POWPOW(base, exponent)Power functionPOW(Growth Rate, 2)

Conditional Logic

IF Statements

Use IF statements to create conditional calculations based on data values.

Syntax: IF(condition, value_if_true, value_if_false)

Supported Operators:

  • Comparison: >, <, >=, <=, =, !=
  • Logical: & (AND), | (OR)

Examples:

Formula
Description
IF(#Unemployment Rate > 5, "High Risk", "Low Risk")Categorizes risk based on unemployment rate
IF(#Revenue > 1000000, #Revenue * 0.1, #Revenue * 0.05)Applies different tax rates based on revenue threshold
IF(#Status = "Active", "Yes", "No")Converts status to Yes/No format
IF(#Age >= 18 & #Income > 50000, "Eligible", "Not Eligible")Complex condition using AND operator

Nested IF Support: Complex nested conditions with proper parentheses handling:

IF(#Score >= 90, "A",
   IF(#Score >= 80, "B",
      IF(#Score >= 70, "C", "F")))

Text Functions

Text functions are available for text field types and enable string manipulation and formatting.

Function
Syntax
Description
Example
CONCATCONCAT(text1, text2, ...)Combines text valuesCONCAT(First Name, " ", Last Name)
UPPERUPPER(text)Converts to uppercaseUPPER(City Name)
LOWERLOWER(text)Converts to lowercaseLOWER(Department)
LENGTHLENGTH(text)Returns character countLENGTH(Description)

Practical Examples

Financial Calculations

Formula
Purpose
(#Revenue - #Costs) / #Revenue * 100Calculate profit margin percentage
IF(#Revenue > 50000, #Revenue * 0.25, #Revenue * 0.15)Progressive tax calculation
ROUND((#Q1 + #Q2 + #Q3 + #Q4) / 4, 2)Rounded quarterly average
#Principal * POW(1 + #Rate, #Years)Compound interest calculation

Text Processing

Formula
Purpose
CONCAT(#First Name, " ", #Last Name)Combine first and last names
IF(#Active = 1, UPPER("Active"), LOWER("Inactive"))Status formatting with case
LENGTH(#Description)Count characters in description
CONCAT(UPPER(#City), ", ", #State)Formatted location string

Statistical Analysis

Formula
Purpose
MAX(#Values) - MIN(#Values)Calculate data range
SQRT(#Variance)Standard deviation from variance
POW(#Final Value / #Initial Value, 1 / #Years) - 1Compound annual growth rate
(#Value - #Mean) / #Standard DeviationZ-score calculation

Using the Formula Editor

Enabling Formulas

  1. Open your dataset in the dataset editor
  2. Click on a column header to edit its properties
  3. Toggle the "Use Formula" switch
  4. Enter your formula expression in the formula editor

Smart Field Suggestions

  • Type # to trigger field suggestions
  • Available fields appear as badges with type indicators
  • Prevents circular references automatically
  • Shows only formula-eligible fields

Real-time Validation

  • Syntax checking as you type
  • Field reference validation
  • Error highlighting and messages
  • Function help tooltips on hover
Tip

Pro Tip: Use the function help system by hovering over functions in the formula editor to see syntax, descriptions, and examples.

Formula Behavior

Automatic Recalculation

Formula columns automatically update when:

  • Referenced columns are modified
  • New data is imported
  • Filters are applied (if formulas reference filtered data)

Error Handling

  • Invalid formulas display "Error" in the column
  • Missing field references show clear error messages
  • Non-numeric values in numeric formulas default to 0
  • Empty text values default to empty strings

Circularity

  • Formulas cannot reference other formula columns to avoid any possibility of circular dependencies.

Best Practices

Formula Design

  • Keep formulas simple and readable
  • Use meaningful field names for easier reference
  • Test formulas with sample data before applying to large datasets
  • Document complex calculations with comments in field names

Performance Optimization

  • Avoid deeply nested IF statements when possible
  • Minimize dependencies between formulas
  • Use appropriate data types for calculations
  • Consider formula complexity for datasets with thousands of rows

Error Prevention

  • Always validate field references before saving
  • Handle edge cases like division by zero or null values
  • Test formulas with various data scenarios
  • Use descriptive error messages for debugging