Skip to content

Finance - P&L Tracking – Customised & Nested Pivot Tables - Alternative

>> Download the sample (Excel)

Finance - P&L Tracking – Customised & Nested Pivot Tables

Section titled “Finance - P&L Tracking – Customised & Nested Pivot Tables”

In this sample, we track Actuals against Budgeted amounts, for each P&L line, showing variances too, in a pivot table. Here, we also need to show additional lines, such as ‘Gross Profit’ and ‘Operating Income’, which do not appear in the source GL data, and other derived measures, such as Cost as % of Net Sales and Op. Profit as % of Net Sales.

This example is like the Finance - P&L Tracking – Customised & Nested Pivot Tables example, except that the DAX formulae in this example calculate the results in a more generalisable and flexible form.

This sample takes the following data inputs:

The dimension tables will be determined by the current structure of the business.

This is where we define the layout and mappings of each P&L line to headers and subheaders, using a predefined numbering system (i.e. the chart of accounts).

The GL here contains both the Actuals and Budgeted data for each month, so both datasets are already available in the same table, in a business-friendly and user-friendly format.

The following specific measures are shown:

  1. Actuals
  2. Budget
  3. Variance $
  4. Variance %

Unlike most of our other samples, the final output here is presented in Excel itself, rather than through a Power BI dashboard, which is great for visuals but not as flexible or sophisticated with tables. For pivot tables alone, it is a matter of preference (in Power BI, these are called matrix tables).

The final file can also be downloaded here, if you would like to review the formulae in detail:

>> Download the sample (Excel)

The final data model used is shown here:

SUM GL Amt :=
SUM ( 'General_Ledger'[Amount] )
GL Amt (Additive Amts) :=
SUMX ( VALUES ( Accounts[Sign] ), [SUM GL Amt] * Accounts[Sign] )
GL Amt (Display Amts):=
SUMX ( VALUES ( Accounts[Report Sign] ), [SUM GL Amt] * Accounts[Report Sign] )
% Additive Total :=
VAR NetSales =
CALCULATE (
[Running Total Amts],
ALL ( Headers ),
Headers[Header] = "Net Sales"
)
VAR HeaderLevelThisStep =
MIN ( Headers[Header ID] )
VAR HeaderLevelPriorStep = HeaderLevelThisStep - 1
VAR Result =
DIVIDE (
CALCULATE (
[GL Amt (Display Amts)],
ALL ( Headers ),
Headers[Header ID] = HeaderLevelPriorStep
),
NetSales
)
RETURN
Result
% Running Total :=
VAR NetSales =
CALCULATE (
[Running Total Amts],
ALL ( Headers ),
Headers[Header] = "Net Sales"
)
VAR Result =
DIVIDE ( [Running Total Amts], NetSales )
RETURN
Result
Magic Additive Total :=
VAR isSubHeaderFiltered =
ISFILTERED ( Subheader[Subheader] )
VAR isHeaderFiltered =
ISFILTERED ( Headers[Header] )
VAR isEitherFiltered =
OR ( isSubHeaderFiltered, isHeaderFiltered )
VAR Result =
IF ( isEitherFiltered, [GL Amt (Display Amts)], [GL Amt (Additive Amts)] )
RETURN
Result
Running Total Amts :=
VAR ThisHeaderID =
MIN ( Headers[Header ID] )
VAR Result =
CALCULATE (
[Magic Additive Total],
ALL ( Headers ),
Headers[Header ID] <= ThisHeaderID
)
RETURN
Result
Total Display Amts :=
VAR CalcType =
MAX ( Headers[Calc Type] ) // should it be a Simple Total or a Running Total
VAR DisplayHeaderCode =
MAX ( Headers[Detail] ) // 1 if the detail should display and 0 if the detail should be hidden
VAR DisplaySubHeaderCode =
MAX ( Subheader[Subheader Detail] ) // 1 if the detail should display and 0 if the detail should be hidden
VAR isSubHeaderVisible =
ISFILTERED ( Subheader[Subheader] ) // we need to know if the SubHeader is trying to show itself
VAR isGLAccountVisible =
ISFILTERED ( Accounts[Account Name] ) // we need to know if the GL Accountis trying to show itself
VAR Result =
SWITCH (
TRUE (),
isSubHeaderVisible = TRUE ()
&& DisplayHeaderCode = 0, BLANK (),
isGLAccountVisible = TRUE ()
&& DisplaySubHeaderCode = 0, BLANK (),
CalcType = 1, [Magic Additive Total],
CalcType = 2, [Running Total Amts],
CalcType = 3, [% Additive Total],
CalcType = 4, [% Running Total]
)
RETURN
Result
Actuals[$] :=
CALCULATE ( [Total Display Amts], Scenarios[ScenarioName] = "Actual" )
Budget[$] :=
CALCULATE ( [Total Display Amts], Scenarios[ScenarioName] = "Budget" )
Variance :=
[Actuals [$]]] - [Budget [$]]]
Variance[%] :=
DIVIDE ( [Variance], [Budget [$]]], BLANK () )