Formulas
Formulas are the power behind dynamic content in EmberBlocks. Use formulas to display calculated values, filter data, create conditional logic, and much more.
What are Formulas?
Section titled “What are Formulas?”Formulas are SQL-like expressions that evaluate to dynamic values. They allow you to:
- Display data from your tables
- Perform calculations
- Create conditional logic
- Filter and aggregate data
- Format values for display
Basic Syntax
Section titled “Basic Syntax”Formulas use double curly braces {{}} to reference data:
{{table.field}} -- Reference a field from a table{{$row.field}} -- Current row in list context{{$row.price * $row.qty}} -- Arithmetic expressionField References
Section titled “Field References”Table Fields
Section titled “Table Fields”Reference fields from any table in your app:
{{customers.name}}{{orders.total}}{{products.price}}Current Row
Section titled “Current Row”In list contexts (like a List component), use $row to reference the current row:
{{$row.name}}{{$row.email}}{{$row.created_at}}Nested References
Section titled “Nested References”Access related data through joins:
{{$row.customer.name}}{{$row.order.items}}Operators
Section titled “Operators”Arithmetic
Section titled “Arithmetic”| Operator | Description | Example |
|---|---|---|
+ | Addition | {{$row.price + $row.tax}} |
- | Subtraction | {{$row.total - $row.discount}} |
* | Multiplication | {{$row.price * $row.quantity}} |
/ | Division | {{$row.total / $row.count}} |
Comparison
Section titled “Comparison”| Operator | Description | Example |
|---|---|---|
= | Equal | {{$row.status = 'active'}} |
!= | Not equal | {{$row.type != 'draft'}} |
< | Less than | {{$row.quantity < 10}} |
> | Greater than | {{$row.price > 100}} |
<= | Less than or equal | {{$row.stock <= 5}} |
>= | Greater than or equal | {{$row.rating >= 4}} |
Logical
Section titled “Logical”| Operator | Description | Example |
|---|---|---|
AND | Logical AND | {{$row.active AND $row.verified}} |
OR | Logical OR | {{$row.admin OR $row.editor}} |
NOT | Logical NOT | {{NOT $row.deleted}} |
Functions
Section titled “Functions”Conditional Functions
Section titled “Conditional Functions”Returns different values based on a condition:
IF(condition, value_if_true, value_if_false)Examples:
IF($row.status = 'active', 'Yes', 'No')IF($row.quantity < 10, 'Low Stock', 'In Stock')IF($row.price > 100, 'Premium', IF($row.price > 50, 'Standard', 'Budget'))COALESCE
Section titled “COALESCE”Returns the first non-null value:
COALESCE(value1, value2, ...)Example:
COALESCE($row.nickname, $row.first_name, 'Unknown')ISNULL
Section titled “ISNULL”Checks if a value is null:
ISNULL($row.deleted_at) -- Returns true if deleted_at is nullAggregation Functions
Section titled “Aggregation Functions”Calculate values across multiple rows:
| Function | Description | Example |
|---|---|---|
SUM() | Total of values | SUM(orders.total) |
COUNT() | Number of rows | COUNT(orders.*) |
AVG() | Average value | AVG(products.price) |
MIN() | Minimum value | MIN(orders.date) |
MAX() | Maximum value | MAX(products.rating) |
String Functions
Section titled “String Functions”| Function | Description | Example |
|---|---|---|
CONCAT() | Join strings | CONCAT($row.first, ' ', $row.last) |
UPPER() | Uppercase | UPPER($row.code) |
LOWER() | Lowercase | LOWER($row.email) |
TRIM() | Remove whitespace | TRIM($row.name) |
SUBSTRING() | Extract portion | SUBSTRING($row.code, 0, 3) |
Date Functions
Section titled “Date Functions”| Function | Description | Example |
|---|---|---|
NOW() | Current date/time | NOW() |
TODAY() | Current date | TODAY() |
DATE_ADD() | Add to date | DATE_ADD($row.due_date, 7, 'days') |
DATE_DIFF() | Difference between dates | DATE_DIFF(NOW(), $row.created_at, 'days') |
FORMAT_DATE() | Format date | FORMAT_DATE($row.date, 'MMM DD, YYYY') |
Type Functions
Section titled “Type Functions”| Function | Description | Example |
|---|---|---|
TEXT() | Convert to text | TEXT($row.quantity) |
NUMBER() | Convert to number | NUMBER($row.price_text) |
DATE() | Convert to date | DATE($row.date_string) |
Data Functions
Section titled “Data Functions”FILTER
Section titled “FILTER”Filter rows from a table:
FILTER(table, condition)Example:
FILTER(orders, orders.status = 'pending')FILTER(products, products.price > 50)LOOKUP
Section titled “LOOKUP”Find a single row matching a condition:
LOOKUP(table, condition)LOOKUP(table, condition).fieldExample:
LOOKUP(users, users.id = $row.user_id).nameLOOKUP(settings, settings.key = 'currency').valueContext Variables
Section titled “Context Variables”Formulas have access to context variables based on where they’re used:
The current row in a list context:
{{$row.id}}{{$row.name}}{{$row.created_at}}The current authenticated user:
{{$user.id}}{{$user.email}}{{$user.display_name}}If connected to an external user table, additional fields are available:
{{$user.department}}{{$user.manager_id}}Current app metadata:
{{$app.name}}{{$app.id}}$selectedRows
Section titled “$selectedRows”In list contexts with selection enabled:
COUNT($selectedRows)SUM($selectedRows.amount)$params
Section titled “$params”URL parameters passed to the view:
{{$params.id}}{{$params.filter}}Formula Contexts
Section titled “Formula Contexts”Different formula locations have different available variables:
| Context | Available Variables |
|---|---|
| Component visibility | All tables, $user, $app |
| List filter | All tables, $user, $app |
| List field display | All tables, $row, $user, $app |
| Text component | All tables, $user, $app |
| Button disabled | All tables, $selectedRows, $user, $app |
| Action parameters | All tables, $row, $selectedRows, $user, $app |
| Default value | All tables, $user, $app |
| Computed value | All tables, $row, $user, $app |
Return Types
Section titled “Return Types”Formulas return different types depending on the expression:
| Type | Description | Example |
|---|---|---|
Text | String value | "Hello World" |
Number | Numeric value | 42, 3.14 |
Boolean | True/false | true, false |
Date | Date value | 2026-01-23 |
DateTime | Date and time | 2026-01-23T10:30:00 |
Record | Single row | LOOKUP(users, ...) |
Array | List of values | [1, 2, 3] |
Table | List of records | FILTER(orders, ...) |
Formula Editor
Section titled “Formula Editor”The formula editor provides tools to help you write formulas:
Features
Section titled “Features”- Syntax highlighting - Color-coded syntax for readability
- Auto-completion - Suggestions for tables, fields, and functions
- Inline documentation - Tooltips with function descriptions
- Validation - Real-time error checking
- Test mode - Preview formula results with sample data
Using the Editor
Section titled “Using the Editor”- Click any formula field to open the editor
- Type your formula or use auto-complete
- Check the preview to verify results
- Click Save to apply
Common Patterns
Section titled “Common Patterns”Display Full Name
Section titled “Display Full Name”CONCAT($row.first_name, ' ', $row.last_name)Calculate Total with Tax
Section titled “Calculate Total with Tax”{{$row.subtotal * (1 + $row.tax_rate)}}Show Status Badge Color
Section titled “Show Status Badge Color”IF($row.status = 'active', 'green', IF($row.status = 'pending', 'yellow', 'red'))Days Until Due
Section titled “Days Until Due”DATE_DIFF($row.due_date, TODAY(), 'days')Filter by Current User
Section titled “Filter by Current User”FILTER(tasks, tasks.assigned_to = $user.id)Conditional Visibility
Section titled “Conditional Visibility”Show a component only for admins:
$user.role = 'admin'Default Value with Current Date
Section titled “Default Value with Current Date”TODAY()Computed Running Total
Section titled “Computed Running Total”SUM(FILTER(transactions, transactions.date <= $row.date).amount)Best Practices
Section titled “Best Practices”Keep Formulas Simple
Section titled “Keep Formulas Simple”- Break complex logic into smaller pieces
- Use intermediate computed fields when helpful
- Comment complex formulas in the description
Performance
Section titled “Performance”- Filter data at the source when possible
- Avoid deeply nested FILTER operations
- Use indexed fields in LOOKUP conditions
Error Handling
Section titled “Error Handling”- Use COALESCE for potentially null values
- Add ISNULL checks before operations
- Provide meaningful default values
Testing
Section titled “Testing”- Test formulas with edge cases
- Verify behavior with empty data
- Check date formulas across time zones
Troubleshooting
Section titled “Troubleshooting”Common Errors
Section titled “Common Errors”| Error | Cause | Solution |
|---|---|---|
| ”Field not found” | Typo in field name | Check spelling and table reference |
| ”Type mismatch” | Wrong data type | Use type conversion functions |
| ”Null reference” | Accessing null value | Add COALESCE or null check |
| ”Syntax error” | Invalid formula syntax | Check parentheses and operators |
Debugging Tips
Section titled “Debugging Tips”- Test small parts of the formula first
- Use the formula preview with sample data
- Check that all referenced tables are available
- Verify field types match expected operations
Next Steps
Section titled “Next Steps”Now that you understand formulas, explore:
- Actions - Use formulas in action parameters
- Components - Apply formulas to component settings
- Data Sources - Understand your data structure