### 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.

A quick thought on this one, I have been doing this for some time but I am wondering whether I am creating unnecessary load by calculating values which are not required in my equation, say for example...

val1 TriggerTag (Boolean)

val2 very complex calculation

val3 another very complex calculation

output if val1 = false then 0 else val2 * val3

Should I have val2 and val3 also checking for val1 (in which case I'd rather write it as straight line code) or does it only evaluate values which are needed by an output? (wishful thinking? or future request!)