Ravindra BagaleCourses & study guides

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 for IF(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

Look, friends: 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, HASONEVALUE to check first, or CONCATENATEX to list several values. It's very simple – just make it a habit.