QuackUIInstall

Margin and rates that total properly

Add margin, margin % and return rate to a model as calculations.

A margin percentage stored per row can’t be summed, and its average is wrong because a £1 sale counts as much as a £1,000 one. Calculate it from the totals at each level.

Add the calculations

Open the model, switch to Editing, and choose New calculation for each of these. They are all measures.

Name Formula
Margin [Net amount] - [Cost amount]
Margin % ([Net amount] - [Cost amount]) / [Net amount]
Return rate [Return quantity] / [Quantity]
Discount rate [Discount amount] / [Gross amount]
The calculation dialog
  1. Wait for this to say Measure · Number.

Return rate uses two fact tables. Each is aggregated on its own before the division, so returns don’t inflate sales.

Use them

They head the Fields pane. Put Margin % in a table and set its format to Percent with one decimal.

Stores with Margin % highlighted
Rules: at least 40.9% positive with an up arrow, below 40.7% negative with a down arrow.

Add a highlight rule with care for rounding. A cell showing 41.0% may hold 0.4096, which isn’t at least 0.41.

Weighted prices

The same idea gives a weighted average price:

[Net amount] / [Quantity]

Averaging Unit price instead gives the mean over order lines, whatever their quantity.

Check it

Make a crosstab of Region by Year with Margin % and both totals. The grand total should equal total margin over total sales, and not the average of the cells.