Forum Discussion
Matrix visual with calculations inside
Hi guys,
I am working on replicating the Profit & Loss report as per below screenshot. There are 2 main requirements:
1. Categorization (Main Category -> Category -> Sub-Category -> Cost Account) needs to be present
2. Date hierarchy to apply on whole table.
As you can see, table itself contains calculations inside the table (Direct Margin, Direct Margin %, etc.). How can this be achieved in Power BI?
Let's start with the red-highighted part of table. What I have tried to create so far:
- I have 2 FACT tables (FACT_Costs and FACT_Revenues). For categories, I have created calculated DIM table DIM_Revenue&CostCategory which is UNION of DIM_CostCategory table to which I have added extra "dummy" rows for Revenues, Direct Margin and Direct Margin %. Number in last column is order of the category within the list.
UNION(
{
("Revenues", "Revenues from charging", "Revenues from charging", "N/A (Revenues)", 0),
("Direct Margin", "Direct Margin", "Direct Margin", "N/A (Direct Margin)", 1.1),
("Direct Margin %", "Direct Margin %", "Direct Margin %", "N/A (Direct Margin %)", 1.2)
},
DISTINCT(
SELECTCOLUMNS(sp_DIM_CostCategory,
"Main Category", "Costs",
"Category", sp_DIM_CostCategory[Cost category],
"Sub-Category", sp_DIM_CostCategory[Cost Account Name],
"Cost Account", sp_DIM_CostCategory[COSTACCOUNT],
"Category Order", sp_DIM_CostCategory[Main Category Order]
))
)
Afterwards, I have created measure to perform calculation based on "selected" row.
Location Direct Margin =
var _revenues = CALCULATE(
SUM('pbi_FACT_Revenues & Costs per Location'[Amount]),
'pbi_FACT_Revenues & Costs per Location'[Cost Account] in {"N/A (Revenues)"}
)
var _costs = CALCULATE(
SUM('pbi_FACT_Revenues & Costs per Location'[Amount]),
'pbi_FACT_Revenues & Costs per Location'[Cost Account] in {"602010"}
)
var _directmargin = CALCULATE(
_revenues - _costs
)
var _directmarginpercentage = CALCULATE(
DIVIDE(_revenues, _revenues - _costs)
)
RETURN
SWITCH(
SELECTEDVALUE('pbi_DIM_Revenue&Cost Category'[Cost Account]),
"N/A (Revenues)", _revenues,
"602010", _costs,
"N/A (Direct Margin)", _directmargin,
"N/A (Direct Margin %)", _directmarginpercentage,
BLANK()
)
However, the result is that rows for Direct Margin and Direct Margin % are blank.
Can you please let me know how can I achieve the desired result?
Thank you
IvanS
IvanS , if want to get data for dummy rows, make sure, dummy rows are in dimension. then ignore filter of dimension and push your calculation
Try to ignore the filter again for margin
var _directmargin = CALCULATE(
_revenues - _costs, all('pbi_FACT_Revenues & Costs per Location')
)I have done similar one here
Power BI How to get the P&L formatting right: https://youtu.be/C9K8uVfthUU
Power BI How to get two columns format Profit and Loss Statement(P&L) right: https://youtu.be/WLg85yiMgHI
1 Reply
- amitchandakSuper User
IvanS , if want to get data for dummy rows, make sure, dummy rows are in dimension. then ignore filter of dimension and push your calculation
Try to ignore the filter again for margin
var _directmargin = CALCULATE(
_revenues - _costs, all('pbi_FACT_Revenues & Costs per Location')
)I have done similar one here
Power BI How to get the P&L formatting right: https://youtu.be/C9K8uVfthUU
Power BI How to get two columns format Profit and Loss Statement(P&L) right: https://youtu.be/WLg85yiMgHI