Prompt
Answer
DAX Formula for Percentage of Cost Subcategories on Total Revenues
Objective
To calculate the percentage of costs (specific subcategories) relative to total revenue using DAX.
Data Structure
Assuming you have a data table with the following relevant columns:
MovementType
: Indicates the type of movement (either "costs" or "revenue").Amount
: Contains the monetary value associated with each movement.
DAX Formula
The following DAX formula calculates the percentage of total costs relative to total revenues.
CostPercentage =
VAR TotalCosts =
CALCULATE(
SUM(Table[Amount]),
Table[MovementType] = "costs"
)
VAR TotalRevenues =
CALCULATE(
SUM(Table[Amount]),
Table[MovementType] = "revenue"
)
RETURN
DIVIDE(TotalCosts, TotalRevenues, 0)
Explanation of the Formula
Variables Definition:
- TotalCosts: This variable calculates the sum of the
Amount
whereMovementType
is "costs". TheCALCULATE
function changes the context of the data to only include rows with costs. - TotalRevenues: This variable sums the
Amount
whereMovementType
is "revenue", similarly using theCALCULATE
function to filter the context.
- TotalCosts: This variable calculates the sum of the
Return Statement:
- The formula uses the
DIVIDE
function to calculate the percentage by dividingTotalCosts
byTotalRevenues
. The third argument (0) specifies the value to return in case of division by zero, preventing any errors.
- The formula uses the
Practical Example
Assume you have the following data in your table named "Financials":
MovementType | Amount |
---|---|
costs | 200 |
costs | 300 |
revenue | 1000 |
revenue | 500 |
- Total Costs = 200 + 300 = 500
- Total Revenues = 1000 + 500 = 1500
Running the formula:
- CostPercentage = 500 / 1500 = 0.3333 or 33.33%
Conclusion
This DAX formula efficiently calculates the percentage of total costs in relation to total revenues, providing insights into the financial performance concerning cost subcategories. For further learning about DAX and its application, consider exploring relevant resources on the Enterprise DNA Platform.
Description
This document presents a DAX formula that computes the percentage of specific cost subcategories relative to total revenues, using data on movement types and monetary values. It also explains the formula's structure and provides a practical example for clarity.