計算グループを使用すると、測定ロジックを簡素化し、レポート機能を向上させることができます。その中でも、選択式は計算の動作を条件に応じて細かく制御します。複数または空の選択式や未選択式を定義し、エラー処理や自動通貨変換などのシナリオを提供します。選択式は計算グループに依存し、ユーザーの選択に基づいて評価されます。選択式の動作を制御する設定もあり、レポートが動的に反応できるようにします。これらの機能を活用し、より良いレポートを作成できます。
計算グループと選択式の活用
計算グループを使ったことがある方は、その力強さを理解していることでしょう。計算ロジックを簡素化し、レポートの機能を向上させるための優れたツールです。しかし、ここで注目すべきは「選択式」の存在です。選択式は、計算の動作を細かく制御するための強力な手段です。
選択式の基本
選択式は、特定の条件が満たされたときに計算の動作を制御します。例えば、ユーザーが計算グループ内で複数の計算項目を選択した場合や、特定の選択が行われなかった場合に追加のロジックを導入します。これにより、エラーハンドリングを改善できるだけでなく、例として自動通貨換算などの有益なデフォルト動作を引き出すことができます。
選択式は計算グループにオプションで定義され、式とオプションの動的フォーマット式で構成されます。
選択式の種類
選択式には、主に以下の2種類があります。
-
複数または空の選択式 (multipleOrEmptySelectionExpression)
ユーザーが同じ計算グループ内で複数の計算項目を選択した場合、またはユーザーの選択とフィルターコンテキストとの間に対立がある場合に評価されます。 - 選択なしの式 (noSelectionExpression)
ユーザーが計算グループ内で何も選択しなかった場合に評価されます。
これらの選択式は、ユーザーが計算グループで行った選択の種類に応じて評価されます。以下の表は、モデルのselectionExpressionBehavior
設定が自動または非視覚の場合の動作を示しています。
選択の種類 | 定義されていない場合の動作 | 定義されている場合の動作 |
---|---|---|
単一選択 | N/A | N/A |
複数選択 | 計算グループはフィルタされません | multipleOrEmptySelectionExpression が評価されます |
空の選択 | 計算グループはフィルタされません | multipleOrEmptySelectionExpression が評価されます |
選択なし | 計算グループはフィルタされません | 指定されたnoSelectionExpression が評価されます |
selectionExpressionBehavior設定
計算グループに定義できる選択式に加えて、selectionExpressionBehavior
というモデルレベルのプロパティが新たに導入される予定です。この設定によって、計算グループでmultipleOrEmptySelectionExpression
が定義されていない場合の動作を制御できます。例えば、以下のようにTMDLを使って定義します。
createOrReplace
model Model
culture: en-US
defaultPowerBIDataSourceVersion: powerBI_V3
discourageImplicitMeasures
sourceQueryCulture: en-US
selectionExpressionBehavior: nonvisual
この設定には3つの値を持つ可能性があります。
- 自動 (Automatic): 既定値で、非視覚と同じです。既存のモデルの動作が変更されません。
- 非視覚 (Nonvisual): 複数または空の選択式が定義されていない場合、計算グループは
SELECTEDMEASURE()
を返し、計算グループでグループ化すると小計値は非表示になります。 - 視覚 (Visual): 複数または空の選択式が定義されていない場合、計算グループは
BLANK()
を返し、計算グループでのグループ化では小計値は選択された測定値を評価して決定されます。
選択式を活用すれば、レポートは動的に反応し、選択が不明瞭な場合でも関連計算を提供できます。
選択式の実例
複数または空の選択
ユーザーが同じ計算グループで複数の選択を行うと、その結果はユーザーが何も選択しなかった場合と同じになります。そこで、計算グループにmultipleOrEmptySelectionExpression
を指定することができます。
IF (
ISFILTERED ( 'MyCalcGroup' ),
"Filters: " &
CONCATENATEX (
FILTERS ( 'MyCalcGroup'[Name] ),
'MyCalcGroup'[Name],
", "
)
)
この設定により、選択肢が複数あるときにその合計が表示され、ユーザーにどのフィルターが適用されているかを通知することができます。
選択なし
選択式を使用すると、自動通貨換算が可能になります。ユーザーが適切な計算グループ項目を選ぶことを忘れても、デフォルトの通貨換算が適用されます。
結論
選択式とselectionExpressionBehavior
設定を利用することで、ユーザーがレポートとどのように対話するかに応じて柔軟に反応する動的なレポートを構築できます。これらの高度な機能を活用して、ぜひユニークなレポートを作成してください。詳細については、選択式のドキュメントを参照してください。
————-
Deep dive into selection expressions for calculation groups | Microsoft Power BI Blog
Source link
Summary of Selection Expressions in Calculation Groups
Overview:
Selection expressions in calculation groups enhance the usability of measures in reporting by allowing developers to define specific behaviors for different selection scenarios. They simplify measure logic and improve error handling, enabling features like automatic currency conversion.
Types of Selection Expressions:
-
Multiple or Empty Selection Expression (multipleOrEmptySelectionExpression):
- Triggered when multiple calculation items are selected or when there’s a conflict with user selections. It provides a way to return a relevant calculation or message.
- No Selection Expression (noSelectionExpression):
- Activated when no items are selected from a calculation group. It allows for default behavior, like automatic currency conversion.
Behavior Conditions:
Depending on whether selection expressions are defined or not, the behavior varies for different selection scenarios:
- Single Selection: No change in behavior.
- Multiple Selection: Evaluates the multipleOrEmptySelectionExpression if defined.
- Empty Selection: Same as multiple selection handling.
- No Selection: Evaluates the noSelectionExpression if defined.
SelectionExpressionBehavior Setting:
This new model-level property influences default behavior in the absence of a defined multipleOrEmptySelection expression. It can take three values:
- Automatic: Default behavior for existing models; may switch to visual in the future.
- Nonvisual: Returns SELECTEDMEASURE() when no multipleOrEmptySelection expression is defined, hiding subtotals.
- Visual: Returns BLANK() in similar cases, allowing subtotal calculations.
Use Cases:
- Multiple or Empty Selections: Allows displaying user-selected filters dynamically.
- No Selections: Enables automatic functioning, such as converting to a default currency even when no explicit selection is made.
Examples:
- Currency Conversion: Users can select currencies, and if none are selected, a predefined default currency is applied.
- Filter Display: A message indicating active filters can be shown when multiple selections are made.
Conclusion:
Overall, selection expressions and the selectionExpressionBehavior setting provide significant flexibility for developers, enhancing reporting capabilities and allowing for a more dynamic user experience. This feature is a powerful addition to handling calculations in reports.