Study FAQ
How can a DAX measure handle ambiguous selections and hierarchy levels?
Also asked as 2
- When should I use HASONEVALUE, ISINSCOPE, or ISBLANK in a measure?
- How do information functions make DAX context assumptions explicit?
Answer
Use information functions to test the condition your business rule actually requires. HASONEVALUE checks for one distinct value in context, ISINSCOPE checks whether a column is the current hierarchy level, and ISBLANK checks for a blank result. These tests answer different questions.
For example, a unit-sensitive calculation might return a result only when one unit is selected:
Revenue for One Unit =
IF ( HASONEVALUE ( Unit[UnitName] ), [Revenue], BLANK () )
This assumes the Unit table and [Revenue] measure exist and that returning blank for ambiguous units is the agreed rule. A hierarchy subtotal needs an appropriate ISINSCOPE test instead; a single filtered value doesn't prove that the visual is at the leaf level.
Specify the output for no selection, multiple selections, missing reference values, and totals. Blank can mean no data or not applicable; converting it to zero changes that meaning and should be a deliberate decision.
Test each branch using controlled selections and a matrix with subtotals. A context guard should expose a real limitation, not conceal unmatched keys, incorrect relationships, or inconsistent source data.
Full explanation
DP-600: Advanced DAX Patterns for Enterprise Semantic Models
Study guide · DP-600
Read the full explanation