身為數據建模師,當您撰寫量值表達式時,可能會遇到無法傳回有意義值的情況。 In these instances, you may be tempted to return a value—like zero—instead. 建議您仔細判斷此設計是否有效且實用。
請考慮下列明確將 BLANK 結果轉換成零的量值定義。
Sales (No Blank) =
IF(
ISBLANK([Sales]),
0,
[Sales]
)
請考慮另一個也將 BLANK 結果轉換為零的度量定義。
Profit Margin =
DIVIDE([Profit], [Sales], 0)
DIVIDE 函式會將 Profit 量值除以 Sales 量值。 如果結果為零或 BLANK,則會傳回第三個自變數—替代結果(這是選擇性的)。 In this example, because zero is passed as the alternate result, the measure is guaranteed to always return a value.
這些量值設計效率不佳,並導致報表設計不佳。
When they're added to a report visual, Power BI attempts to retrieve all groupings within the filter context. 大型查詢結果的評估和擷取通常會導致報表轉譯變慢。 每個範例量值都會有效地將疏鬆計算轉換成密集計算,迫使Power BI使用比必要更多的記憶體。
Also, too many groupings often overwhelm your report users.
Let's see what happens when the Profit Margin measure is added to a table visual, grouping by customer.
The table visual displays an overwhelming number of rows. (實際上模型中有18,484個客戶,因此數據表會嘗試顯示所有客戶。請注意,檢視中的客戶尚未達成任何銷售。 Yet, because the Profit Margin measure always returns a value, they are displayed.
Note
當視覺效果中顯示太多數據點時,Power BI 可能會使用數據縮減策略來移除或摘要大型查詢結果。 For more information, see Data point limits and strategies by visual type.
讓我們看看當改進 利潤率 量值定義時會發生什麼事。 It now returns a value only when the Sales measure isn't BLANK (or zero).
Profit Margin =
DIVIDE([Profit], [Sales])
The table visual now displays only customers who have made sales within the current filter context. 改進的量值可為您的報表使用者提供更有效率且實用的體驗。
Tip
When necessary, you can configure a visual to display all groupings (that return values or BLANK) within the filter context by enabling the Show Items With No Data option.
Recommendation
It's recommended that your measures return BLANK when a meaningful value cannot be returned.
此設計方法很有效率,可讓Power BI更快速地轉譯報表。 Also, returning BLANK is better because report visuals—by default—eliminate groupings when summarizations are BLANK.
相關內容
- Learning path: Use DAX in Power BI Desktop
- Questions? Try asking the Power BI Community
- Suggestions? 貢獻想法以改善 Power BI