Build a measure step by step with VAR and RETURN
Name the pieces of a calculation with variables to work out how much of the list price is given away in discounts.
You will learn to
- Store intermediate results in variables with VAR
- Return a final result with RETURN
- Calculate a weighted rate from two totals
How it works
Longer measures are easier to read, and to get right, when you name each step. `VAR Name = expression` stores a result; `RETURN` says what the measure finally gives back.
A variable is calculated **once**, in the filter context where it is defined, and then reused. Writing `[Gross Sales]` twice in one formula is both slower and harder to follow than one variable used twice.
In this model `[Gross Sales]` is revenue at list price and `[Total Sales]` is revenue after discounts. The gap between them is what was given away.
Practice it hands-on with a real data model and a live report that updates as you type.
Average Price =
VAR Units = SUM(Sales[Quantity])
VAR Revenue = [Total Sales]
RETURN DIVIDE(Revenue, Units)