# Make AF Analytics more readable - Break up your calculations

Posted by asoudek in AF Community Library on Aug 31, 2016 2:52:50 PM### Make your calculations more readable and understandable

It is not easy to try to read and understand an equation that is very long (those of you who have experience with the PI Performance Equations can attest to this). There are several ways to make equations more readable. The first is to use comments, which are described in a Topic later in this document. The second is to split up complex equations into several Variables, and the last, is to split up an expression for a Variable into multiple lines.

**Splitting into multiple Variables:**

The expression in the Figure below calculates the critical gas flow rate for a well. It is pretty messy and not easy to read.

Splitting it up into several Variables and expressions will make it more readable. The Figure below shows the same equation split up into several Variables, making it much easier to read. We also get the results for each Variable defined, which also makes it easier to debug the equation. Additionally, we can map each Variable to an Attribute for an **On Demand** calculation (Analysis Data Reference) or to write to a **PI Tag**.

**Splitting expression into multiple lines:**

The expression you have may not be that complex, but it can take up a lot of real estate and can be difficult to read. A typical example is an expression with nested **IF** statements. Either we can use the approach described above to split it up into multiple Variables or we can split up the expression into multiple lines in the same Variable. The expression in the Figure below is not completely visible because it has a couple of nested **IF **statements. Even if we click inside it to edit it, it will wrap around to the next line.

A good approach is to use the ** Shift-Enter** key combination at strategic points in the expression to split up the expression into several lines. A much more readable result is shown in the Figure below. To indent a line you must use the

**Space**bar. (

**Note:**you cannot use the

**Tab**key).

We can also put a comment at the end of each line, as described in **AF Analytics - Commenting Your Work** blog.

### Using Variables to construct your calculations makes them more readable

It is not easy to read an equation that has Attribute names that are long. The equations can also become very messy. The solution is to define the Attributes as Variables.

The expression in the Figure below calculates the critical gas flow rate for a well. It is pretty messy and not easy to read.

By assigning the Attributes to Variables makes the equation simpler to read and understand.

## Comments