13. DAX: Data Analysis Expressions
13.13 VALUES, SELECTEDVALUE, HASONEVALUE
VALUES(<column>)– returns the distinct values of a column visible in the current filter context (plus a blank row if there are unmatched keys).DISTINCT(<column>)– similar, but does not add that blank row.HASONEVALUE(<column>)– TRUE if exactly one distinct value is visible.SELECTEDVALUE(<column>, [alternate])– returns the value if exactly one is visible, otherwise the alternate result (BLANK by default). It is shorthand forIF(HASONEVALUE(col), VALUES(col), alternate).
Categories Sold = COUNTROWS(VALUES(Product[Category]))
Selected City = SELECTEDVALUE(DarkStore[City], "All Cities")
Selected Platform = SELECTEDVALUE(Orders[Platform], "Blinkit & Amazon Now")
Dynamic Title = "Quick-Commerce Overview – " & [Selected Platform] & " | " & [Selected City]
City Check =
IF(HASONEVALUE(DarkStore[City]), VALUES(DarkStore[City]), "Multiple cities selected")
Dynamic titles
Use a measure like [Dynamic Title] in any visual title: Format › General › Title › fx (conditional formatting button) › Format style: Field value › choose the measure.
Ravindra Bagale's Tip
He bagha, mitrano: using VALUES in a card or title without handling multiple selections gives "A table of multiple values was supplied where a single value was expected". Use SELECTEDVALUE with a default, or HASONEVALUE to check first, or CONCATENATEX to list several values. Ekdum simple aahe, fakt savay lavun ghya.