# Formulas in Fibery

Fibery supports formulas. So far Formula field supports `Number`

only (`Decimal`

or `Integer`

). More data types will be added later (`Date`

, `Text`

, etc).

Formula is a Field, and it means you can do the same things with Formula Field as with all other fields. For example, you can display Formula Field on entity card, filter and sort by Formula Field, use it inside Charts.

To create a formula, navigate to any Type and click Add Field or Relation, then select Formula:

You will see Formula field creation form. In this form you should specify Field Name, Field Type (Integer or Decimal) and Formula itself:

Formula setup can be challenging, so let’s explore some examples based on the following domain:

Here we have `Product`

with a collection of Epics, and Epic has a collection of Features. Let’s say, we have Estimate field in Feature and want to calculate Total Estimate inside Epic. The formula will look like that:

Total Estimate Field inside Epic:Features.Sum(Estimate)

Now we want to add Total Estimate Field into Product entity to roll-up all Epics. Here is how you do it

Total Estimate Field inside ProductEpics.Sum([Total Estimate])

Here are more examples:

Inside Epic we want to calculate effort of all completed Features. We create Completed Effort Formula Field:

Completed Effort Field inside Epic:Features.Filter(State.Final =true).Sum(Estimate)

And let’s define Not Done Effort Field

Not Done Effort Field inside Epic:Features.Filter(State.Final !=true).Sum(Estimate)

Now we can specify Epic Progress Field like this:

Progress Field inside Epic:[Completed Effort] / [Total Estimate] *100

# Reference

## Basic math operations

Nothing fancy here, usual operators are supported (`*, -, +, /`

)

`Effort * Risk / Complexity.Value`

Velocity - [Assigned Effort]

## Access Collection and Fields

Use dot notation to access Collections and Fields:

`Epic.Estimate`

Epic.Product.Value * [Own Value]

If you have space in Field or Collection name, you will have to use [], like this:

`[User Stories]`

[Total Effort]

## Aggregates by collections

You can use special operators to aggregate collections (`Sum`

, `Avg`

, `Count`

, `Max`

, `Min`

)

`Features.Count()`

Features.Sum(Estimate)

## Filter inside collections

You can use `Filter`

operator (with `AND`

operator) to extract subsets from collections:

Sum of Estimates of all not completed Features:Features.Filter(State.Final !=true).Sum(Estimate)Count of all high complexity Features without Estimates: Features.Filter(Estimate =0AND Complexity.Name ="High").Count()