Ravindra BagaleCourses & study guides मराठी Track your progress

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".

First look at the data (before → after):

SELECTEDVALUE in Power BI with example (dynamic title): before and after tables, fictional Blinkit Maharashtra data

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:

  1. New measure: Title (formula above).
  2. Select a chart. Format › General › Title › fx.
  3. Format style: Field value. Choose the Title measure.
  4. Change the slicer and watch the 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 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.

Loading DAX practice tasks...

  1. Which department is picked? (Easy): Slicer: Department = Cardiology. Measure: Picked Dept = the one selected Department.
  2. More than one picked (Easy): Slicer: Department = Cardiology and Dermatology. Measure: Picked Dept = selected Department, or "Many" if not exactly one.
  3. Count of patients (Easy): Slicer: Insured = Yes. Measure: Patients = number of rows in the VALUES of Visits[Patient].
  4. Exactly one department? (Medium): Slicer: Department = Cardiology and Dermatology. Measure: One Dept = TRUE if only one Department is selected.
  5. Dynamic card title (Medium): Slicer: City = Delhi. Measure: Title = "Fees for " joined with the selected City, or "All cities" if none or many.
  6. Visit types per department (Medium): Shown per Department. Measure: Visit Types = number of different VisitType values.
  7. Doctors per city (Medium): Shown per City. Measure: Doctors Seen = number of different DoctorName values.
  8. 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.
  9. Fees per doctor (Hard): Shown per Department. Measure: Fees per Doctor = [Total Fees] ÷ number of different DoctorID values.
  10. Cardiology premium (Hard): Shown per Department. Measure: Adjusted Fees = [Total Fees] × 1.1 when the selected Department is "Cardiology", else [Total Fees].

Ravi Sir's Cards for this lesson

मराठी cards