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
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.
Ravindra Bagale's Tip – मराठी
हे बघा मित्रांनो: multiple selections handle न करता card किंवा title मध्ये VALUES वापरलं तर "A table of multiple values was supplied where a single value was expected" येतं. Default सोबत SELECTEDVALUE वापरा, आधी तपासण्यासाठी HASONEVALUE, किंवा अनेक values ची list करण्यासाठी CONCATENATEX वापरा. एकदम simple आहे, फक्त सवय लावून घ्या.
Ravindra Bagale's Tip – हिंदी
देखो दोस्तों: multiple selections handle किए बिना card या title में VALUES इस्तेमाल करने पर "A table of multiple values was supplied where a single value was expected" आता है. Default के साथ SELECTEDVALUE इस्तेमाल करो, पहले check करने के लिए HASONEVALUE, या कई values की list के लिए CONCATENATEX. बहुत आसान है, बस आदत बना लो.