Working with formulas

Learn how to work with formulas to manipulate data and streamline logic in Nordcraft.

Create a formula

Create a formula

To create a new formula in Nordcraft:

  1. 1
    Navigate to the data panel with no element selected
  2. 2
    Click the + button in the Formulas section
  3. 3
    Enter a name for your formula
  4. 4
    (Optional) Add inputs with test values to use while building the formula
  5. 5
    (Optional) Expose the formula in context to make it available to child components
  6. 6
    (Optional) Delete the formula when it is no longer needed
  7. 7
    Define the formula logic using the formula editor
Tip

Test values for formula inputs are useful during development as they allow you to verify your formula works correctly without needing to set up actual data flows.

Accessing data in formulas

In the formula editor, you can access various data sources within your component:

  • Inputs: Formula-specific inputs
  • Attributes: Values passed into the component
  • Variables: Variables defined in the component
  • API data: Results from API calls
  • Context values: Data exposed by parent components
  • Component formulas: Formulas defined in the component
  • Global formulas: Formulas defined at the global project level

Reusable formulas

To keep your formulas efficient and maintainable, you can define reusable formulas to use throughout your project. If you find yourself repeating the same formula logic in multiple places, follow these steps:

  1. 1
    Create a component-level formula in the data panel
  2. 2
    Give it a descriptive name
  3. 3
    Define its logic once
  4. 4
    Use it wherever needed

Reusable formulas provide these benefits:

  • Reduce duplication in your project
  • Improve maintainability (changes in one place affect all usages)
  • Enhance performance through result caching (due to their pure function nature)
Example

Discover how a reusable formula formats the box office value, ensuring consistent formatting throughout the component wherever it is used.

Nested formulas

You can create nested formulas where one formula can call another:

  • Build small, single-responsibility formulas that perform specific tasks
  • Combine these smaller formulas to create more complex logic
  • This modular approach makes your formula logic more readable and easier to maintain
Tip

By breaking down complex operations into smaller, reusable pieces, you can build sophisticated functionality while keeping each formula simple and focused on a single responsibility.

Example

Learn how this nested formula works, combining different formulas to filter 90s movies, calculate the average box office, and format the result.

Common formula examples

The formula editor supports many JavaScript-like operations. Below are some common formula examples to help you get started.

Map formula

The Map method returns a new array by applying a function to each element in the original array.

Example

Check out how the Map formula transforms each item in an array using the Set function, with the results displayed in a new array.

Filter formula

The Filter method returns a new array with elements that pass a specific condition.

Example

See how the Filter formula selects specific items from an array based on a condition, returning a new array with only the matching elements.

Sort formula

The Sort by method arranges array elements in a specific order.

Example

Discover how the Sort by formula arranges items in an array based on a specified order, returning a new sorted array.

Reduce formula

The Reduce method applies a function to reduce an array to a single value.

Example

See how the Reduce formula transforms an array into a single value by applying a function to each element.

Find formula

The Find formula searches through an array of items, applying a callback formula to each item, and returning the first item where the callback formula returns true.

Example

The Find formula searches an array for the first matching element and returns it.

Get formula

The Get formula extracts a value from an object, array or string at a specified path, returning null if no value is found.

Example

Check out how the Get formula extracts a value from an object, array or string at a specified path.

05/02/2025
Edit article
Help Forum