Daily DAX : Day 420 HASONEVALUE
Power BI DAX Function: HASONEVALUE()
Syntax: HASONEVALUE(<columnName>)
Returns: TRUE or FALSE
What does HASONEVALUE() do?
It checks whether a column has exactly one distinct value in the current filter context.
- TRUE → Only one unique value exists (e.g., when you are looking at a single customer, single month, etc.)
- FALSE → There are multiple values or no values (e.g., total level, multiple selections)
Common Use Cases
| Use Case | Why HASONEVALUE() is Needed | Example Measure |
|---|---|---|
| Show a value only at detailed level (not in totals) | Totals have many values → HASONEVALUE returns FALSE |
Sales Amount (Detail Only) =
IF(
HASONEVALUE(Customer[CustomerKey]),
SUM(Sales[SalesAmount]),
BLANK()
)
|
| Display customer name in a card visual only when one customer is selected | Avoid showing concatenated names when multiple customers are selected |
Selected Customer Name =
IF(
HASONEVALUE(Customer[Customer Name]),
SELECTEDVALUE(Customer[Customer Name]),
"Multiple Customers Selected"
)
|
| Conditional formatting or logic based on single selection | Enable certain calculations only when filtered to one item |
Rank Only for Single Product =
IF(
HASONEVALUE(Product[ProductName]),
RANKX(ALL(Product), [Total Sales], , DESC),
BLANK()
)
|
Quick Comparison
| Function | Returns TRUE when… |
|---|---|
HASONEVALUE(column) | Exactly 1 distinct value |
ISINSCOPE(level) | You are at that level or below in hierarchy |
ISCROSSFILTERED(column) | Any filter is applied on the column |
Best Practice Tip
Use HASONEVALUE() together with SELECTEDVALUE() for clean, user-friendly reports:
Dynamic Title =
IF(
HASONEVALUE(Date[Year]),
"Sales for Year " & SELECTEDVALUE(Date[Year]),
"Total Sales Across Years"
)
Now you can confidently use HASONEVALUE() to make your Power BI reports smarter and cleaner!
Comments
Post a Comment