>> 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.
Data Inputs
Section titled “Data Inputs”This sample takes the following data inputs:
Dimensions
Section titled “Dimensions”The dimension tables will be determined by the current structure of the business.
![]()
Accounts Structure
Section titled “Accounts Structure”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).
![]()
![]()
General Ledger
Section titled “General Ledger”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.
![]()
P&L Tracking Measures
Section titled “P&L Tracking Measures”The following specific measures are shown:
- Actuals
- Budget
- Variance $
- Variance %
Dashboard - Snippet
Section titled “Dashboard - Snippet”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)
![]()
Data Model - Snippet
Section titled “Data Model - Snippet”The final data model used is shown here:
![]()
Measures
Section titled “Measures”SUM GL Amt
Section titled “SUM GL Amt”SUM GL Amt :=SUM ( 'General_Ledger'[Amount] )GL Amt (Additive Amts)
Section titled “GL Amt (Additive Amts)”GL Amt (Additive Amts) :=SUMX ( VALUES ( Accounts[Sign] ), [SUM GL Amt] * Accounts[Sign] )GL Amt (Display Amts)
Section titled “GL Amt (Display Amts)”GL Amt (Display Amts):=SUMX ( VALUES ( Accounts[Report Sign] ), [SUM GL Amt] * Accounts[Report Sign] )% Additive Total
Section titled “% Additive Total”% Additive Total :=VAR NetSales = CALCULATE ( [Running Total Amts], ALL ( Headers ), Headers[Header] = "Net Sales" )VAR HeaderLevelThisStep = MIN ( Headers[Header ID] )VAR HeaderLevelPriorStep = HeaderLevelThisStep - 1VAR Result = DIVIDE ( CALCULATE ( [GL Amt (Display Amts)], ALL ( Headers ), Headers[Header ID] = HeaderLevelPriorStep ), NetSales )RETURN Result% Running Total
Section titled “% Running Total”% Running Total :=VAR NetSales = CALCULATE ( [Running Total Amts], ALL ( Headers ), Headers[Header] = "Net Sales" )VAR Result = DIVIDE ( [Running Total Amts], NetSales )RETURN ResultMagic Additive Total
Section titled “Magic Additive Total”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 ResultRunning Total Amts
Section titled “Running Total Amts”Running Total Amts :=VAR ThisHeaderID = MIN ( Headers[Header ID] )VAR Result = CALCULATE ( [Magic Additive Total], ALL ( Headers ), Headers[Header ID] <= ThisHeaderID )RETURN ResultTotal Display Amts
Section titled “Total Display Amts”Total Display Amts :=VAR CalcType = MAX ( Headers[Calc Type] ) // should it be a Simple Total or a Running TotalVAR DisplayHeaderCode = MAX ( Headers[Detail] ) // 1 if the detail should display and 0 if the detail should be hiddenVAR DisplaySubHeaderCode = MAX ( Subheader[Subheader Detail] ) // 1 if the detail should display and 0 if the detail should be hiddenVAR isSubHeaderVisible = ISFILTERED ( Subheader[Subheader] ) // we need to know if the SubHeader is trying to show itselfVAR isGLAccountVisible = ISFILTERED ( Accounts[Account Name] ) // we need to know if the GL Accountis trying to show itselfVAR 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 ResultActuals[$]
Section titled “Actuals[$]”Actuals[$] :=CALCULATE ( [Total Display Amts], Scenarios[ScenarioName] = "Actual" )Budget[$]
Section titled “Budget[$]”Budget[$] :=CALCULATE ( [Total Display Amts], Scenarios[ScenarioName] = "Budget" )Variance
Section titled “Variance”Variance :=[Actuals [$]]] - [Budget [$]]]Variance[%]
Section titled “Variance[%]”Variance[%] :=DIVIDE ( [Variance], [Budget [$]]], BLANK () )