Calculate margins and balances at the correct grain
A finance report combines flows such as revenue with snapshots such as inventory on hand.
Calculate margins and balances at the correct grain
A finance report combines flows such as revenue with snapshots such as inventory on hand. Decide what a total means across dates and products before writing its DAX expression.
The recording explains why a month that ends on a non-trading day needs the last available balance in the period.
Work through the decision
Store A makes 10 margin on 100 revenue and B makes 180 on 900. Is the overall margin 15%?
Check your reasoning
Combined margin is 190 divided by 1,000, or 19%. The simple average of the two store percentages gives 15% and weights their very different revenue equally.
Decisions and tradeoffs
- Last nonblank balance
- Use the most recent eligible snapshot within the period for a closing balance. Adding successive daily balances overstates stock.
- DIVIDE on aggregated measures
- Compute a rate from its aggregate numerator and denominator, handling zero according to the measure’s meaning.
- CALCULATE with a filter argument
- Modify the filter context for evaluation of a measure, considering whether filters replace or intersect existing selections.
- SUMX across the visible line rows
- Multiply quantity and price at line grain before adding amounts in the current filter context.
- Calculation group
- A calculation group can apply common transformations such as current period and prior year across compatible measures.
Calculate margin under the current selection
Use a pair of additive amounts to derive the percentage at each level of the matrix.
Gross margin = SUM(Sales[Revenue]) - SUM(Sales[Cost])
Margin rate = DIVIDE([Gross margin], SUM(Sales[Revenue]))
For stores with revenues 100 and 900 and costs 90 and 720, the total margin amount is 190. The total rate is 19%. If revenue is zero, DIVIDE returns blank unless you provide an alternate result.
Practice each guide skill
Work through these exercises in the order of the published guide. The checklist numbers are local references.
- Define total quantity as a measure and test it by product and at the grand total.
- Use CALCULATE to evaluate a base measure for a chosen status; check whether existing filters are overwritten or intersected.
- Compare current and prior-period revenue against the common calendar. Decide how to display missing comparative periods.
- Use median and average on a skewed order sample and explain which statistic describes a typical order better.
- Calculate the latest nonblank balance within the reporting period; decide whether individual entities need different last dates.
- Generate a quick measure and inspect the resulting DAX against a hand-calculated slice.
- Compare a refresh-time classification column with a computed date table; inspect their effect on model size.
- Implement a shared prior-year calculation for compatible measures and verify currency and count outputs separately.
Official objectives for this lesson
Related lesson · Model shared ownership and reusable calculations
Calculate margins and balances at the correct grain quiz
Answer 3 questions. Check each answer for an explanation.