Forum Discussion
Grand Total Not Calculating Correctly
Hello,
I am creating a P&L budget using a drilldown matrix. For Expense, I have different rules for each "Sub Expense category" eg to exclude certain Cost Centres and Activity Type Areas. To do this, I have used SELECTVALUE to know which "Sub Expense category" rule to apply.
I create a measure to calculate the 'Budget Year 1'. The totals are correct at a row level, but it calculates the total Expense wrongly as it is ignoring the "Sub Expense category" rules, and also does not calculate at a grand total level. How do I get this to work and is this possible in Power BI? I want the expense to total at every level, the total Expense (ie -7 + 49) and finally Revenue - Expense (-7+49+60) at a grand total level.
| 1st Cat | 2nd Cat | 3rd Cat | Budget Year 1 |
| Expense | Exception Salary | Full Time Staff | -7 |
| Total | -7 | ||
| Salary | Full Time Staff | -49 | |
| Total | -49 | ||
| Total | <not calculating> | ||
| Revenue | Internal Revenue | Student Fees | 60 |
| Total | 60 | ||
| Total | 60 | ||
| Total | <not calculating> |
Budget Year 1 =
var firstCategory = SELECTEDVALUE('P&L Structure'[1stCat])
var secondCategory = SELECTEDVALUE('P&L Structure'[2ndCat])
var revenue = SUMX(Budget, Budget[Amount])
var expense =
SWITCH(TRUE(),
secondCategory = "Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9900 && Budget[ActivityArea] = "AA1"))),
secondCategory = "Exception Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9600 && Budget[ActivityArea] = "AA1"))))
var result =
SWITCH(TRUE(),
firstCategory = "Revenue", revenue,
firstCategory = "Expense", expense)
RETURN
result
Attached is my example pbix file.
https://drive.google.com/file/d/1nWPTQJglcJX7oHoBAJuJBNIjGs79AKed/view?usp=sharing
Anonymous , Try like
var firstCategory = SELECTEDVALUE('P&L Structure'[1stCat]) var secondCategory = SELECTEDVALUE('P&L Structure'[2ndCat]) var revenue = SUMX(Budget, Budget[Amount]) var expense = SWITCH(TRUE(), secondCategory = "Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9900 && Budget[ActivityArea] = "AA1"))), secondCategory = "Exception Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9600 && Budget[ActivityArea] = "AA1")))) var result = sumx(summarize('P&L Structure','P&L Structure'[1stCat],'P&L Structure'[2ndCat],'P&L Structure'[3rdCat],"_1", SWITCH(TRUE(), firstCategory = "Revenue", revenue, firstCategory = "Expense", expense)),[_1]) RETURN result
1 Reply
- amitchandakSuper User
Anonymous , Try like
var firstCategory = SELECTEDVALUE('P&L Structure'[1stCat]) var secondCategory = SELECTEDVALUE('P&L Structure'[2ndCat]) var revenue = SUMX(Budget, Budget[Amount]) var expense = SWITCH(TRUE(), secondCategory = "Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9900 && Budget[ActivityArea] = "AA1"))), secondCategory = "Exception Salary", - CALCULATE(SUMX(Budget, Budget[Amount]), FILTER(Budget, NOT (Budget[CostCentre] = 9600 && Budget[ActivityArea] = "AA1")))) var result = sumx(summarize('P&L Structure','P&L Structure'[1stCat],'P&L Structure'[2ndCat],'P&L Structure'[3rdCat],"_1", SWITCH(TRUE(), firstCategory = "Revenue", revenue, firstCategory = "Expense", expense)),[_1]) RETURN result