Streak 0 daysPoints 0

Lesson16/59
Complete itVariables and RETURN

Readable measures with VAR

New functionsVAR, RETURN, DIVIDE
StatusNot started

VAR name = expression stores a value once, and RETURN gives the result. Variables make a measure readable, and they are evaluated once, in the context where they are defined.

Here the two variables are given: the revenue and the cost of the cell. What’s missing is the result: the margin as a share of revenue.

Your task

Complete Margin % so that it returns (Revenue minus Cost) divided by Revenue, using the two variables.

*1*1*1*1SALEST1 · 420 ROWSSalesKeyNUMOrder DateDATEShip DateDATEProductKeyNUMCustomerKeyNUMQuantityNUMUnit PriceNUMPRODUCTT2 · 8 ROWSProductKeyNUMProductTEXTCategoryTEXTColorTEXTList PriceNUMStandard CostNUMCUSTOMERT3 · 10 ROWSCustomerKeyNUMCustomerTEXTCountryTEXTSegmentTEXTDATET4 · 731 ROWSDateDATEYearNUMQuarterTEXTMonthTEXTMonth NumberNUMNOTES1Filters flow from 1 to *, alongthe arrow: Product filters Sales.2Select a column or a measureto insert it at the cursor.3Measures in this model:[Sales Amount][Total Cost]Key columnFact tableSALES MODEL · STAR SCHEMASHEET 1 OF 1

About this exercise

You practise variables and return with VAR, RETURN and DIVIDE. The exercise runs on a small bike-shop model with a Sales fact table and Product, Customer and Date dimensions, the same star schema in every lesson.

Your measure, Margin %, fills a Power BI-style matrix grouped by Customer[Segment] and Product[Category]. As in a real report, each cell evaluates the measure in its own filter context, and the subtotals and the grand total are evaluated again in theirs rather than added up. When you check your answer, every cell is compared with the expected value, wrong cells are marked, and the hint is about the mistake you made.

Measures that already exist in the model: Sales Amount and Total Cost. Reference them in square brackets, for example [Sales Amount].

Where you start

Margin % =
VAR Revenue = [Sales Amount]
VAR Cost = [Total Cost]
RETURN

The result to build

Expected result for Margin %
Category
SegmentAccessoriesBikesClothingTotal
Business64.5%46.1%62.6%49.4%
Consumer66.4%48.1%63.6%51.2%
Total64.7%46.4%62.8%49.7%

Last updated 10 November 2026

Opening the exercise…