Building client-facing revenue dashboards in Airtable is a great way to show value. However, nothing looks more unprofessional than a dashboard filled with NaN, Infinity, or blank error values. In this tutorial, I'll show you how to write defensive formulas to prevent these calculations from breaking.
Why Airtable Throws 'Infinity' and 'NaN' Errors
These errors occur due to mathematical and data entry issues:
- Division by Zero: If you calculate Cost Per Acquisition (CPA) using
Spend / Conversions, and a project has 0 conversions, Airtable attempts to divide by zero, resulting inInfinity. - Blank Values: If a record has blank fields, Airtable evaluates the blank as zero or undefined, causing calculations to yield
NaN(Not a Number).
The Defensive Formula Pattern
To write bulletproof formulas, you must use a defensive coding pattern. Always check that your divisor is not blank and is greater than zero before performing division.
Here is the standard formula pattern for CPA tracking:
IF(
AND({Conversions} > 0, {Spend} >= 0),
{Spend} / {Conversions},
0
)/pre>
p>This formula checks if conversions are greater than zero. If true, it performs the division; otherwise, it returns a clean 0 or blank.
Practical Advanced Formula Examples
1. Gross Margin Percentage Tracking
Use the following formula to calculate profit margins safely:
IF(
{Revenue} > 0,
ROUND(({Revenue} - {Cost}) / {Revenue}, 4),
0
)/pre>
h3>2. Percentage Progress Rendering/h3>
p>When displaying progress on dashboards, formatting is key. Use this script-like formula to render a progress bar text indicator:
IF(
{Total Tasks} > 0,
REPT("■", ROUND(({Completed Tasks} / {Total Tasks}) * 10, 0)) &
REPT("□", 10 - ROUND(({Completed Tasks} / {Total Tasks}) * 10, 0)) &
" " & ROUND(({Completed Tasks} / {Total Tasks}) * 100, 0) & "%",
"░ Empty Base"
)/pre>
h2>Conclusion/h2>
p>Writing defensive formulas requires a few extra keystrokes, but it ensures your enterprise dashboards remain functional and presentable. Apply these patterns to safeguard your business intelligence reporting.
