Excel 2024: Compare Budget Versus Actual via Power Pivot


June 07, 2024 - by

Excel 2024: Compare Budget Versus Actual via Power Pivot

Budgets are done at the top level revenue by product line by region by month. Actuals accumulate slowly over time invoice by invoice, line item by line item. Comparing the small Budget file to the voluminous Actual data has been a pain forever. I love this trick from Rob Collie, aka PowerPivotPro.com.

To set up the example, you have a 54-row budget table: 1 row per month per region per product.

The Budget table is four columns and 54 rows: Product, Region, Date, Budget.
The Budget table is four columns and 54 rows: Product, Region, Date, Budget.

The invoice file is at the detail level: 422 rows so far this year.

The Invoice table has a thousand rows. Columns ar Invoice, Date, Region, Product, Customer.
The Invoice table has a thousand rows. Columns ar Invoice, Date, Region, Product, Customer.

There is no VLOOKUP in the world that will ever let you match these two data sets. But, thanks to Power Pivot (aka the Data Model in Excel 2013+), this becomes easy.

You need to create tiny little tables that I call joiners to link the two larger data sets. In my case, Product, Region, and Date are in common between the two tables. The Product table is a tiny four-cell table. Ditto for Region. Create each of those by copying data from one table and using Remove Duplicates.


A cartoon shows a big ugly mean Actuals sitting at a table with a tiny meek Budget. They won't get along. But in the middle, trying to talk to both of them are three tiny joiner tables.
A cartoon shows a big ugly mean Actuals sitting at a table with a tiny meek Budget. They won't get along. But in the middle, trying to talk to both of them are three tiny joiner tables.

Illustration: George Berlin

The three joiner tables. The Product table is a Product heading and three rows by 1 column: Gadget, WhatsIt and Widget. The Region table is a Region heading and three rows of Central, East, West. The Calendar table is larger. It has two columns: Date and Month. It continues beyond the edge of the figure, including every date found in either table.
The three joiner tables. The Product table is a Product heading and three rows by 1 column: Gadget, WhatsIt and Widget. The Region table is a Region heading and three rows of Central, East, West. The Calendar table is larger. It has two columns: Date and Month. It continues beyond the edge of the figure, including every date found in either table.


The calendar table on the right was actually tougher to create. The budget data has one row per month, always falling on the end of the month. The invoice data shows daily dates, usually weekdays. So, I had to copy the Date field from both data sets into a single column and then remove duplicates to make sure that all dates are represented. I then used =TEXT(J4,"YYYY-MM") to create a Month column from the daily dates.

If you don't have the full Power Pivot add-in, you need to create a pivot table from the Budget table and select the checkbox for Add This Data to the Data Model.

As you create the pivot table, choose the box for Add This Data To The Data Model.
As you create the pivot table, choose the box for Add This Data To The Data Model.

As discussed in the previous tip, as you add fields to the pivot table, you will have to define six relationships. While you could do this with six visits to the Create Relationship dialog, I fired up my Power Pivot add-in and used the diagram view to define the six relationships.

You will be creating six relationships. Create three relationships from the Budget table to the three joiner tables. Create three relationships from the Actuals table to the three joiner tables.
You will be creating six relationships. Create three relationships from the Budget table to the three joiner tables. Create three relationships from the Actuals table to the three joiner tables.

Here is the key to making all of this work: You are free to use the numeric fields from Budget and from Actual. But if you want to show Region, Product, or Month in the pivot table, they must come from the joiner tables!

Here is a pivot table with data coming from five tables. Column A is coming from the Region joiner. Row 2 is coming from the Calendar joiner. The Product slicer is from the Product joiner. The Budget numbers come from the Budget table, and the Actual numbers come from the Invoice table.

This pivot table has Region and Budget/Actual down the side. Months across the top. A Product slicer at the bottom.
This pivot table has Region and Budget/Actual down the side. Months across the top. A Product slicer at the bottom.

This works because the joiner tables apply filters to the Budget and Actual table. It is a beautiful technique and shows that Power Pivot is not just for big data.

Bonus Tip: Portable Formulas

You can use the DAX formula language to create new calculated fields. From the Power Pivot tab in the Ribbon, choose Measures, New Measure. If you don't have the Power Pivot tab in the Ribbon, you can right-click the Table name in the PivotTable Fields pane and choose Add Measure.

Give the field a name, such as Variance. When you go to type the formula, type =[. As soon as you type the square bracket, Excel gives you a list of fields to choose from.

Note that you can also assign a numeric format to these calculated fields. Wouldn't it be great if regular pivot tables brought the numeric formatting from the underlying data?

Defining a new calculated field or Measure. The formula is =[Sum of Revenue]-[Sum of Budget]. You can specify the formula is Currency with 0 decimal places.
Defining a new calculated field or Measure. The formula is =[Sum of Revenue]-[Sum of Budget]. You can specify the formula is Currency with 0 decimal places.

In the next calculation, VariancePercent is reusing the Variance field that you just defined.

The formula for VariancePercent is [Variance]/[Sum of Budget]. This one is formatted as a Number, Percentage, with 1 decimal place.
The formula for VariancePercent is [Variance]/[Sum of Budget]. This one is formatted as a Number, Percentage, with 1 decimal place.

So far, you've added several calculated fields to the pivot table, as shown below.

The pivot table shows Budget, Revenue, Variance, Variance Percent.
The pivot table shows Budget, Revenue, Variance, Variance Percent.

But you don't have to leave any of those fields in the pivot table. If your manager only cares about the variance percentage, you can remove all of the other numeric fields.

In this version of the pivot table, all of the intermediate calculations are gone, leaving only Variance Percent.
In this version of the pivot table, all of the intermediate calculations are gone, leaving only Variance Percent.

Note that the DAX in this bonus tip is barely scratching the surface of what is possible. If you want to explore Power Pivot, you need to get a copy of Supercharge Power BI by Matt Allington.

Thanks to Rob Collie for teaching me this feature. Find Rob at www.PowerPivotPro.com.

Bonus Tip: Text in the Values of a Pivot Table

Another amazing use for a measure in a Data Model pivot table is to use the CONCATENATEX function to move text into the values area of a pivot table.

In this data set, there is an original and revised value for each sales rep.

The source data has Region, Market, Rep, Version and Code. The code is text. The version is either Original or Revised.
The source data has Region, Market, Rep, Version and Code. The code is text. The version is either Original or Revised.
'

Insert a pivot table and check the box for Add This Data To The Data Model. Drag Rep to the Rows and Version to Columns.

'

Build a pivot table with Rep down the side, Version across the top. Currently, there are no fields in the Value area yet.
Build a pivot table with Rep down the side, Version across the top. Currently, there are no fields in the Value area yet.

The Grand Totals get really ugly, so you should remove them now. On the Design tab, use Grand Totals, Off For Rows and Columns.

'

On the Design tab, choose Grand Totals, Off for Rows and Columns.
On the Design tab, choose Grand Totals, Off for Rows and Columns.

In the Pivot Table Fields panel, right-click the Table name and choose Add Measure.

Right click the Table1 heading in the Pivot Table Field list and choose Add Measure....
Right click the Table1 heading in the Pivot Table Field list and choose Add Measure....

The formula for the measure is =CONCATENATEX(Values(Table1[Code]),Table1[Code],", "). The VALUES function makes sure that you don't get duplicate values in the answer.

The measure name is AllText. The Formula is =CONCATENATEX(Values(Table1[Code],Table1[Code),", ")
The measure name is AllText. The Formula is =CONCATENATEX(Values(Table1[Code],Table1[Code),", ")

After defining the measure, drag the measure to the Values area. In this case, each cell only has one value.

Success! Words are being reported in the values area of the pivot table.
Success! Words are being reported in the values area of the pivot table.

However, if you rearrange the pivot table, you might have multiple values joined in a cell.

This pivot table has Market in column A instead of rep. There are two words per market for original and two words per market for Revised. The Atlanta cell for Original is Fig, Cherry. The Atlanta cell for Revised is Fig, Orange.
This pivot table has Market in column A instead of rep. There are two words per market for original and two words per market for Revised. The Atlanta cell for Original is Fig, Cherry. The Atlanta cell for Revised is Fig, Orange.

Caution: A cell may not contain more than 32,768 characters. If you have a large data set, it is possible that this Grand Total of this measure will be more than 32,768 characters. The Excel team never anticipated that a pivot table cell would contain more than this many characters, but thanks to DAX and CONCATENATEX, it can happen. When it does happen, Excel can not draw the pivot table. But - there is no error message - the pivot table simply stops updating until you get rid of the Grand Total or somehow make the largest cell be less than 32,768 characters.


This article is an excerpt from MrExcel 2024 Igniting Excel

Title photo by Heather Barnes on Unsplash