Column Formulas
Overview
Column formulas allow you to generate column values dynamically based on mathematical expressions. Formulas can reference other columns, use built-in functions, and automatically update when source data changes. The formula system provides over 600 functions from the GNU Scientific Library (GSL), including mathematical, statistical, logical, and special functions.
Basic Syntax
Creating a Formula
To create a formula column:
Right-click on a column header → Formula
Enter your formula expression
Map variable names to actual columns
Enable Auto Update to recalculate automatically
Note
Columns can be referenced from any spreadsheet in the project, not just the current one. When mapping variables, you can select columns from different spreadsheets.
Syntax Rules
Variables: Reference other columns (e.g.,
x,y,data)Operators:
+,-,*,/,^(power)Functions: Use semicolon
;to separate arguments (not comma)Constants:
pi,e, and others from GSLCross-spreadsheet: Variables can reference columns from any spreadsheet in the project
Examples
Basic arithmetic:
x * 2 + y
Distance calculation:
sqrt(x^2 + y^2)
Conditional logic:
if(temperature > 0; 1; 0)
Normalization (z-score):
(x - mean(x)) / stdev(x)
Moving average:
sma(10; temperature)
Date extraction:
year(date_column)
Trigonometry with degree conversion:
sin(angle_degrees * pi / 180)
Cross-spreadsheet reference:
# Variables can reference columns from different spreadsheets
# Example: temperature from Spreadsheet1 minus baseline from Spreadsheet2
temp - baseline
# Where 'temp' is mapped to: Project/Spreadsheet1/Temperature
# And 'baseline' is mapped to: Project/Spreadsheet2/Baseline
Available Functions
Standard Mathematical Functions
Function |
Description |
Example |
|---|---|---|
|
Square root |
|
|
Power xy |
|
|
Exponential ex |
|
|
Natural logarithm |
|
|
Base-10 logarithm |
|
|
Absolute value |
|
|
Round up |
|
|
Round down |
|
|
Round to nearest |
|
|
Round to n decimals |
|
|
Sign (-1, 0, 1) |
|
Comparison and Logical Functions
Function |
Description |
Returns |
|---|---|---|
|
Conditional expression |
Value based on condition |
|
Logical AND |
1.0 or 0.0 |
|
Logical OR |
1.0 or 0.0 |
|
Logical NOT |
1.0 or 0.0 |
|
Equality test |
1.0 or 0.0 |
|
Greater than |
1.0 or 0.0 |
|
Less than |
1.0 or 0.0 |
|
In range (exclusive) |
1.0 or 0.0 |
|
In range (inclusive) |
1.0 or 0.0 |
Note
You can also use operators: >, >=, <, <=, ==, !=
Example: Nested conditions
if(score >= 80; 2; if(score >= 60; 1; 0))
Column Statistics
Compute statistics over entire columns. These return a constant value repeated for all rows.
Function |
Description |
Example |
|---|---|---|
|
Number of values |
|
|
Sum of values |
|
|
Minimum value |
|
|
Maximum value |
|
|
Arithmetic mean |
|
|
Median |
|
|
Standard deviation |
|
|
Variance |
|
|
First quartile (Q1) |
|
|
Third quartile (Q3) |
|
|
Interquartile range |
|
|
p-th percentile |
|
|
Skewness |
|
|
Kurtosis |
|
Example: Detect outliers
if(fabs(x - mean(x)) > 2 * stdev(x); 1; 0)
Moving Statistics
Operate on sliding windows of data.
Function |
Description |
Example |
|---|---|---|
|
Simple moving average |
|
|
Moving minimum |
|
|
Moving maximum |
|
|
Moving range |
|
Cell Access Functions
Access individual cell values for lag/lead operations and custom calculations.
Function |
Description |
Args |
|---|---|---|
|
Access cell at index in another column |
2 |
|
Access cell with default if out of range |
3 |
|
Access cell in current column |
1 |
|
Access cell in current column with default |
2 |
Examples:
# Access previous value (lag 1)
cell_curr_column_with_default(i-1; 0)
# Access next value (lead 1)
cell_curr_column_with_default(i+1; 0)
# Difference from previous value
x - cell_curr_column_with_default(i-1; x)
# Access another column at offset
cell_with_default(i-2; 0; temperature)
# Moving difference (current minus 5 rows back)
x - cell_curr_column_with_default(i-5; x)
Trigonometric Functions
All angles in radians. Available functions: sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, and many more.
Example: Convert degrees to radians
sin(angle_degrees * pi / 180)
Example: Hypotenuse
hypot(x; y) # Equivalent to sqrt(x^2 + y^2)
Datetime Functions
Work with dates and times. Dates are represented as days since 1900-01-01.
Creation Functions
today()- Current datenow()- Current date and timedate(year; month; day)- Create datetime(hour; minute; second)- Create time
Extraction Functions
year(date)- Extract yearmonth(date)- Extract month (1-12)day(date)- Extract day (1-31)weekday(date)- Day of week (1=Monday)hour(datetime)- Extract hourminute(datetime)- Extract minute
Calculation Functions
datedif(start; end; unit)- Date differencenetworkdays(start; end)- Business days between dates
Examples
Age calculation:
year(today()) - year(birthdate)
Quarter extraction:
ceil(month(date) / 3)
Special Functions
LabPlot provides 600+ specialized functions through GSL:
Bessel Functions:
J0,J1,Jn,Y0,Y1,Yn,I0,K0, etc.Gamma and Beta:
gamma,lgamma,beta,fact(factorial),choose(binomial)Error Functions:
erf,erfc,voigtElliptic Integrals:
Kc,Ec,F,ELegendre Polynomials:
P1,P2,PlHypergeometric:
hyperg_0F1,hyperg_1F1,hyperg_2F1Probability Distributions: PDF, CDF, and quantile functions for Gaussian, Student’s t, Chi-squared, F, Exponential, Gamma, Beta, Poisson, Binomial, and many more
Random Number Generation
Generate random values from various distributions:
rand()- Random integer [0, RAND_MAX]drand()- Random float [0, 1]randflat(a; b)- Uniform random [a, b]randgaussian(sigma)- Gaussian randomrandpoisson(mu)- Poisson randomrandbinomial(p; n)- Binomial random
Example: Add noise
x + randgaussian(0.1)
Text Columns and Formulas
Formula results are always numeric. For text columns, use numeric codes with value labels:
Create a text column for the result
Use a numeric formula:
if(score >= 80; 2; if(score >= 60; 1; 0))Add value labels to the column:
0 → “Fail”
1 → “Pass”
2 → “Excellent”
The spreadsheet displays text while storing numbers internally
This approach works for:
Conditional text assignment
Categorical data classification
Status indicators
Tips and Best Practices
Performance
Disable Auto Update during data entry for large datasets
Re-enable when done editing
Column statistics are cached and fast to use
Accuracy
Use
log1p(x)instead oflog(1+x)for small xUse
hypot(x; y)instead ofsqrt(x^2+y^2)to avoid overflowUse
equalE(a; b; epsilon)for floating-point comparisons
Debugging
Test formulas on small datasets first
Check for division by zero:
if(equal(x; 0); 0; y/x)Check for negative square roots:
if(x >= 0; sqrt(x); 0)
Common Patterns
Clamp values to range:
if(x < min; min; if(x > max; max; x))
Distance from mean in standard deviations:
fabs(x - mean(x)) / stdev(x)
Percentage change:
(current - previous) / previous * 100
Running total:
sum(x) / size(x) * i # where i is row index
Additional Resources
For a complete reference of all 620 available functions with detailed descriptions and examples, see the LabPlot source code.