HASONEVALUE
Whether the filter context leaves exactly one value in a column.
Group: Information. Compatible with DAX.
Syntax
HASONEVALUE ( <columnName> )
| Parameter | Type | Description |
|---|---|---|
columnName | Column | The column whose values are counted in the current filter context. |
Returns
Boolean. TRUE when exactly one value of the column is left, FALSE when none or several are.
Remarks
- The one value may come from a filter on the column itself or from filters on other columns that reach it (cross-filtering): a category with a single product leaves one product.
- Its usual use is as a guard:
IF ( HASONEVALUE ( Products[Product] ), VALUES ( Products[Product] ) )shows the product's name on a product's row and nothing on the total.SELECTEDVALUEdoes the same in one call. - A row context is not a filter: in
ADDCOLUMNS ( VALUES ( Products[Product] ), ... )it is FALSE untilCALCULATEturns the row into a filter. - When the filters leave no value at all, it is FALSE.
- To know whether a visual groups by the column, rather than whether one value is left, use
ISINSCOPE.
Examples
A name on each row, a text on the total
EVALUATE
SUMMARIZECOLUMNS (
ROLLUPADDISSUBTOTAL ( Products[Product], "Total" ),
"Liters", [Liters sold],
"Shown as", IF ( HASONEVALUE ( Products[Product] ), VALUES ( Products[Product] ), "All products" )
)
ORDER BY [Total], Products[Product]
| Products[Product] | Total | Liters | Shown as |
|---|---|---|---|
| Cider | FALSE | 301074 | Cider |
| IPA | FALSE | 331884 | IPA |
| Lettøl | FALSE | 169179 | Lettøl |
| Pils | FALSE | 1004326 | Pils |
| (blank) | TRUE | 1806463 | All products |
One value left by another column's filter
Beer has three products, Cider one; no product is called Stout.
EVALUATE
ROW (
"Category Cider", CALCULATE ( HASONEVALUE ( Products[Product] ), Products[Category] = "Cider" ),
"Category Beer", CALCULATE ( HASONEVALUE ( Products[Product] ), Products[Category] = "Beer" ),
"Stout", CALCULATE ( HASONEVALUE ( Products[Product] ), Products[Product] = "Stout" )
)
| Category Cider | Category Beer | Stout |
|---|---|---|
| TRUE | FALSE | FALSE |