13. DAX: Data Analysis Expressions
13.13 VALUES, SELECTEDVALUE and HASONEVALUE in Power BI with Example
SELECTEDVALUE in Power BI with example (dynamic title) — in 30 seconds
What: SELECTEDVALUE returns the one value selected in a column. If none or many are selected, it returns your fallback text.
Why: A title like "Sales for Pune" changes with the slicer. Managers like that.
Tiny example: Slicer = Pune → "Sales for Pune". Slicer = Pune + Mumbai → "Sales for All cities".
SELECTEDVALUE in Power BI with example (dynamic title) — 30 सेकंदात
काय: SELECTEDVALUE column मध्ये निवडलेली एकच value परत देतो. काही नाही किंवा अनेक निवडले तर तुमचा fallback text देतो.
का: "Sales for Pune" सारखं title slicer सोबत बदलतं. Managers ना ते आवडतं.
छोटं उदाहरण: Slicer = Pune → "Sales for Pune". Slicer = Pune + Mumbai → "Sales for All cities".
SELECTEDVALUE in Power BI with example (dynamic title) — 30 सेकंड में
क्या: SELECTEDVALUE column में चुनी गई एक value लौटाता है. कुछ नहीं या कई चुने हों तो आपका fallback text देता है.
क्यों: "Sales for Pune" जैसा title slicer के साथ बदलता है. Managers को यह पसंद आता है.
छोटा उदाहरण: Slicer = Pune → "Sales for Pune". Slicer = Pune + Mumbai → "Sales for All cities".
First look at the data (before → after):
Same before / after tables as text
Before — City slicer selection
| Case | Selected cities |
|---|---|
| A | Pune |
| B | Pune, Mumbai |
| C | (nothing) |
About this data: This table uses columns: Case, Selected cities. This table uses columns: Case, Title measure shows. Values shown are the lesson examples already on this page (not a new dataset).
Formula / click path
Title = "Sales for " & SELECTEDVALUE(DarkStore[City], "All cities")
After — Title text
| Case | Title measure shows |
|---|---|
| A | Sales for Pune |
| B | Sales for All cities |
| C | Sales for All cities |
Do it step by step:
- New measure: Title (formula above).
- Select a chart. Format › General › Title › fx.
- Format style: Field value. Choose the Title measure.
- Change the slicer and watch the title.
एक-एक step करून बघा:
- New measure: Title (वरचा formula).
- एक chart निवडा. Format › General › Title › fx.
- Format style: Field value. Title measure निवडा.
- Slicer बदला आणि title बघा.
एक-एक step करके देखिए:
- New measure: Title (ऊपर वाला formula).
- एक chart चुनिए. Format › General › Title › fx.
- Format style: Field value. Title measure चुनिए.
- Slicer बदलिए और title देखिए.
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. बहुत आसान है, बस आदत बना लो.
Loading DAX practice tasks...
- Which department is picked? (Easy): Slicer: Department = Cardiology. Measure: Picked Dept = the one selected Department.
- More than one picked (Easy): Slicer: Department = Cardiology and Dermatology. Measure: Picked Dept = selected Department, or "Many" if not exactly one.
- Count of patients (Easy): Slicer: Insured = Yes. Measure: Patients = number of rows in the VALUES of Visits[Patient].
- Exactly one department? (Medium): Slicer: Department = Cardiology and Dermatology. Measure: One Dept = TRUE if only one Department is selected.
- Dynamic card title (Medium): Slicer: City = Delhi. Measure: Title = "Fees for " joined with the selected City, or "All cities" if none or many.
- Visit types per department (Medium): Shown per Department. Measure: Visit Types = number of different VisitType values.
- Doctors per city (Medium): Shown per City. Measure: Doctors Seen = number of different DoctorName values.
- Fee only for single-doctor rows (Hard): Shown per Department. Measure: Single Doctor Fees = [Total Fees] only when exactly one DoctorName is in the row, else blank.
- Fees per doctor (Hard): Shown per Department. Measure: Fees per Doctor = [Total Fees] ÷ number of different DoctorID values.
- Cardiology premium (Hard): Shown per Department. Measure: Adjusted Fees = [Total Fees] × 1.1 when the selected Department is "Cardiology", else [Total Fees].
Revision card