# Insert calculated columns

With Inforiver, you can insert a new calculated row, column, or measure at the visual level in your Power BI table or matrix-style reports without writing DAX. The rows, measures, and columns so created can also be formatted, rearranged, and utilized for downstream calculations.

The Excel-like formula engine supports 50+ functions (logical, boolean, math functions, and more). The formula editor provides syntax, examples, and features such as autocomplete, multi-line support, and more to help users create and troubleshoot formulas.

{% hint style="info" %}
Refer to [formula syntax](https://docs.inforiver.com/formula-syntax) for a detailed list of functions, operators, and identifiers that can be used for calculations.
{% endhint %}

### 1. Visual measure

Let us take this example, where we have sales data for two years, 2024 and 2023, by quarter. We will now try to insert a measure that calculates the percentage variance using the formula (2024 Actuals - 2023 Actuals) / 2023 Actuals.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FtYKfH3tdOm3DETBYeRMP%2Fimage.png?alt=media&#x26;token=869ee64d-f10a-41c9-9d38-d1061589d5ed" alt=""><figcaption><p>Sales actuals by quarter</p></figcaption></figure>

**STEP 1:** To insert a measure, select **Insert Formula** from the **Insert** ribbon. A side panel opens on the right.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Ff6wF2GN3jqmuh7OlpeD0%2Fimage.png?alt=media&#x26;token=f0583948-d757-426b-9476-31ba57476d7d" alt=""><figcaption><p>Insert formula option in the toolbar</p></figcaption></figure>

**STEP 2:** You will see two options in the **Insert as** field: **Visual Measure** (the default) and **Visual Column**. Let us go ahead with the default option - **Visual Measure.**

The visual measure behaves like a measure, except that it is inserted directly in your visual (bypassing the data model). In the image below, note that this new measure is inserted under each quarter.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FficBpu0eE9Kbnv8xVqma%2Fimage.png?alt=media&#x26;token=26588c25-4b63-4668-b949-747a77c60573" alt=""><figcaption><p>Inserting a visual measure</p></figcaption></figure>

**STEP 3:** Once you place the cursor inside the formula editor, you will see a context assistant pop-up. You can access dimension/measure references or functions through this context assistant.

<div><figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FGidHyoRgJGie5PdMLiK3%2Fimage.png?alt=media&#x26;token=09d8c936-766b-46d6-8ee8-fa421da5ac4d" alt=""><figcaption><p>List of references</p></figcaption></figure> <figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FTaiUTrj5CZ2u9TiwOVKq%2FListofFunctions.png?alt=media&#x26;token=2d662398-c999-4a9a-9bba-67c0aeafe9dc" alt=""><figcaption><p>List of functions</p></figcaption></figure></div>

**STEP 4:** Let us go ahead and start typing in values. As you key in a formula, the **References** list automatically refreshes to show a narrower set of options.&#x20;

{% hint style="info" %}
You can directly select a column from the table to insert in the formula editor. Note that measures can not be referred to this way. To insert a visual measure or a visual column in your formula, you need to use the **References** tab in the context assistant.
{% endhint %}

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FvmCaqi8m2urWdxhepOz9%2Fimage.png?alt=media&#x26;token=1b09f20f-033a-4ae2-969d-be3855a90aba" alt=""><figcaption><p>Using intellisense to narrow down the reference list</p></figcaption></figure>

**STEP 5:** We will go ahead and complete the formula as shown below. The rectangular parentheses in the formula indicate that these are not normal text but references to other measures.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FdIWtArDTrHdz6QAxjAiG%2Fimage.png?alt=media&#x26;token=36a343fe-c3ff-4358-a176-c0931fec2e81" alt=""><figcaption><p>Enter the formulaa</p></figcaption></figure>

**STEP 6:** Give the calculated measure a relevant name, say 'Variance %', and click **Create**.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Fr2N5dPUuCnfnBVbLAm2G%2Fimage.png?alt=media&#x26;token=a7011db3-f09f-4917-8edb-78b3a21deb79" alt=""><figcaption><p>Naming a calculated column</p></figcaption></figure>

**STEP 7:** You would have now inserted a calculated measure in your report. However, you will notice that the values are in absolute numbers and not in percentage terms.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FKfGU06fvAkSN2HZF8UHt%2Fimage.png?alt=media&#x26;token=02cd4af3-7daf-47cc-9442-b41e759dc3b5" alt=""><figcaption><p>Formula measure created</p></figcaption></figure>

**STEP 8:** To convert the values to a percentage format, click on the **%** icon from the **Home** tab. As you do this, you will also notice that the formula bar at the top of the matrix shows how the measure is calculated.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FZVMHK59kyO3jPBhjxLyG%2Fimage.png?alt=media&#x26;token=b925bc30-12ad-4508-9360-61a632a2f609" alt=""><figcaption><p>Formula measure converted to percentage</p></figcaption></figure>

We have successfully inserted a calculated measure at the visual level in our Power BI matrix report.

### 2. Visual column

A calculated column works differently from a calculated measure. Let's consider two examples.

#### Example 1:

**STEP 1:** Let us calculate the quarter-on-quarter change from Q3 to Q4. Select the **Visual Column** option. Note that a visual column always appears at the end, outside any category or category hierarchies seen in columns.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2F23PjMPENeoHTQSHCtDZq%2Fimage.png?alt=media&#x26;token=247ed5ac-73f1-4a3b-bc83-77de9dd5ff6c" alt=""><figcaption><p>Inserting a visual column</p></figcaption></figure>

**STEP 2:** You will also notice that the **References** section is a bit different. While creating a [new measure](#1.-visual-measure), the **References** section only listed the available measures (2024 Actuals and 2023 Actuals). This time, it displays every instance of the individual measures (e.g., Q2 - 2024 Actuals, Q3 - 2023 Actuals, etc.). Using this, you can traverse right up to the leaf node of any column hierarchy.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2F2PyQCo4X6yVtNCsNHiSy%2Fimage.png?alt=media&#x26;token=13f790c0-bd43-48f2-a052-6d3e21bb721c" alt=""><figcaption><p>References when creating a visual column</p></figcaption></figure>

**STEP 3:** Enter a title and the formula and click **Create**.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FclA2wMVtRtvvBVXar3uU%2Fimage.png?alt=media&#x26;token=35b3788d-270e-456b-bf77-bfb3de1557b7" alt=""><figcaption><p>Configuring a calculated column</p></figcaption></figure>

**STEP 4:** You will see the values updated in the report.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Fui8XRhFJg9w73Di2eTWE%2Fimage.png?alt=media&#x26;token=a08f770a-1e9a-4f0c-b5f5-6ba5159959e8" alt=""><figcaption><p>Visual column created</p></figcaption></figure>

#### Example 2:

Let's consider an example where we use built-in functions. In the example below, we want to insert a column that displays the multiplier - 2022 Actuals/2022 Plan.&#x20;

**STEP 1:** Click **Insert Formula**. Notice that there is no option to insert as a visual measure or column. This is because the report doesn't have a column hierarchy.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FjNtx1IQdVgVKtqLRlSoe%2Fimage.png?alt=media&#x26;token=28aa8b10-1bd9-40a0-8992-2e6c049ef8e2" alt=""><figcaption><p>Visual columns are automatically created when the report doesn't have a column hierarchy</p></figcaption></figure>

**STEP 2:** Enter the title and the formula. Click **Create**.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FbxyWuQVTOhDDlPUqv6az%2Fimage.png?alt=media&#x26;token=50fe9720-4d82-4749-8dec-123a7cf1bfac" alt=""><figcaption></figcaption></figure>

**STEP 3:** Notice that there are Div/0! errors for two of the rows. There are two ways to deal with calculation errors.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Fz1utAv3rBqNIvwJJnvsH%2Fimage.png?alt=media&#x26;token=5f3f068d-1e5b-4894-99a9-36dd0c679916" alt=""><figcaption><p>Calculation errors in the visual column</p></figcaption></figure>

**i) Display settings -> Suppress calculation errors**

In the **Home** tab, click on **Display** settings. In the side panel, go to the **Numbers** tab. Turn on the **Suppress Calculation Errors** toggle. A new field called **Custom Error Text** is enabled.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FnJotP6S8bk5AvjX2hkuy%2F4.2.25%20Column.png?alt=media&#x26;token=9fe1b220-4ea3-4c31-a0d8-4f912b273bcd" alt=""><figcaption><p>Suppress calculation errors</p></figcaption></figure>

You can define a custom text, such as 'N/A', 'ERROR', or leave it blank. In the image below, we have entered 0. You can see the changes in the rows.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FedBgPHvsN2o1iqDrDOdC%2Fimage.png?alt=media&#x26;token=80776d3e-8c57-4888-be5f-d9faaadbbd5a" alt=""><figcaption><p>Replacing error messages with custom text</p></figcaption></figure>

**ii) Using IFNA function**

Another way to handle calculation errors is by using the IFNA function. When an expression results in an error, you can replace it with a value as shown below.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FcAKAC4RsDCs89dnBmxZS%2Fimage.png?alt=media&#x26;token=0b5686e8-f02d-4057-819b-3d0bc68522d3" alt=""><figcaption><p>Handling errors with the IFNA function</p></figcaption></figure>

**iii) Using the IF function**

Another indirect approach would be to use IF/nested IF statements to define the value when the expression results in an error.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FpVCR2Io2KijeDQuNNZIz%2Fimage.png?alt=media&#x26;token=44b7695f-53ac-43a6-855a-a2ea014368f2" alt=""><figcaption><p>IF function to handle errors</p></figcaption></figure>

### **3. Row and column aggregation for formula measures** &#x20;

Inforiver automatically sets the row aggregation to formula and the column aggregation to sum for formula measures. You can override the default aggregation a required.&#x20;

Note: When you select weighted average as the row aggregation type, the column aggregation will be set to weighted average and cannot be overridden.&#x20;

You can view and edit the aggregation for formula measures from the Manage aggregation interface. [Learn more about aggregation features in Inforiver.](https://docs.inforiver.com/working-with-inforiver/manage-aggregations)

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2F3vqy9RfYo4ErT01Lnkjj%2Fimage.png?alt=media&#x26;token=93e7384f-1a31-464e-93cd-39e11e8534d5" alt=""><figcaption><p>Row and column aggregation for formula fields</p></figcaption></figure>

#### Resources

[Insert Formulas, Columns and Aggregation](https://www.youtube.com/watch?v=hjPAbuYJUSc)

[Visual calculations using Inforiver](https://inforiver.com/webinars/visual-level-formula-calculations-powerbi/)

[Calculate remaining budget in Power BI (without using DAX)](https://inforiver.com/blog/general/calculating-remaining-budget-powerbi/)

[Insert calculated measure or column in Power BI](https://inforiver.com/blog/feature-highlights/insert-visual-measure-column-calculations-in-microsoft-power-bi/)
