VARによる変数
CoddyのPower BIジャーニー「CALCULATEを使ったDAX」セクションの一部。レッスン 18/24。
VAR Name = expressionはステップに名前を付け、RETURNは結果を返します。
Margin % =
VAR Cost = SUMX(Sales, Sales[Quantity] * RELATED(Products[UnitCost]))
VAR Profit = [Revenue] - Cost
RETURN DIVIDE(Profit, [Revenue])各変数はメジャーのフィルターの下で一度計算され、その上にある変数を使用できます。
チャレンジ
中級変数を使ってMargin %を作成します。Cost変数(数量に商品ごとの単価を掛けた値を、行ごとに計算)、Profit変数(RevenueからCostを引いた値)を作成し、その後、ProfitをRevenueで割った値を返します。カテゴリごとに確認されます。
自分で試してみよう
レポートデータモデル
Margin % =| Category | Margin % |
|---|---|
| Coffee | |
| Tea | |
| Bakery | |
| Merch | |
| 合計 |
フィールド
- Sales
- Revenue
- Total Units
- Customers
- Products
- ProductID
- Product
- Category
- UnitPrice
- UnitCost
- Stores
- Customers
- Dates
- Targets