Prompt
Answer
DAX Formula for Percentage of Cost Categories on Total Revenue
Objective
To calculate the percentage of cost categories relative to the total amount of revenue in a dataset containing a column that classifies movements as either "costs" or "revenue."
DAX Formula
The following DAX formula achieves this calculation:
CostPercentage =
VAR TotalRevenue =
CALCULATE(
SUM(Table[Amount]),
Table[MovementType] = "revenue"
)
VAR TotalCosts =
CALCULATE(
SUM(Table[Amount]),
Table[MovementType] = "costs"
)
RETURN
DIVIDE(TotalCosts, TotalRevenue, 0)
Explanation of the Formula
Variables:
- TotalRevenue: This variable uses the
CALCULATE
function to compute the sum of theAmount
column, filtered to include only rows where theMovementType
is "revenue." - TotalCosts: Similar to
TotalRevenue
, this variable calculates the sum of theAmount
column but filters for "costs."
- TotalRevenue: This variable uses the
Return Statement:
- The formula returns the result of the
DIVIDE
function, which dividesTotalCosts
byTotalRevenue
. The third argument in theDIVIDE
function (0) specifies that ifTotalRevenue
is zero, it should return 0 instead of an error.
- The formula returns the result of the
Practical Example
Assume you have a table named FinancialData
structured as follows:
MovementType | Amount |
---|---|
revenue | 1000 |
revenue | 2000 |
costs | 300 |
costs | 700 |
Using the above DAX formula:
TotalRevenue calculation:
- SUM of Revenue = 1000 + 2000 = 3000
TotalCosts calculation:
- SUM of Costs = 300 + 700 = 1000
Percentage Calculation:
- CostPercentage = DIVIDE(1000, 3000, 0) = 0.3333 or 33.33%
Conclusion
The DAX formula provided effectively calculates the percentage of cost categories against total revenue, offering insights into financial performance. For further learning and mastery of DAX and other data analysis techniques, consider exploring the courses on the Enterprise DNA Platform.
Description
This DAX formula calculates the percentage of costs relative to total revenue in a dataset. It involves summing costs and revenues, then dividing costs by revenue while handling cases of zero revenue to avoid errors.