Power BI Advanced AnalyticsLesson 37 of 53
Lesson 37 of 53

Virtual Table Functions: VALUES, DISTINCT & SELECTEDVALUE

Overview & Learning Objectives

In DAX, functions do not just operate on numbers—they operate on virtual tables existing in memory. Three of the most essential table and scalar functions are `VALUES()` (returns unique values in filter context including the blank row), `DISTINCT()` (returns unique values strictly from the table), and `SELECTEDVALUE()` (returns a single value if only one is filtered, or a fallback).

  • Master `VALUES(Column)` and understand why it includes the "blank row" for referential integrity.
  • Contrast `VALUES()` with `DISTINCT()`.
  • Use `SELECTEDVALUE()` to build dynamic visual titles and parameter switches.

Industry Standard

Standard: Analytics standards at Amazon and Microsoft mandate using `SELECTEDVALUE(Column, Fallback)` for dynamic titles rather than legacy `IF(HASONEVALUE(...), VALUES(...), Fallback)` patterns.

Real-World Example: Scoop & Swirl Dynamic Reporting

Scoop & Swirl has a City slicer. If the user clicks "Mumbai", the chart title should say "Sales for Mumbai". If multiple cities are selected, say "Sales for All Cities".

Slicer SelectionSELECTEDVALUE() ResultVisual Title Displayed
"Mumbai" (Single selection)"Mumbai""Sales Performance for Mumbai"
"Delhi" & "Mumbai" (Multiple)"All Cities" (Fallback)"Sales Performance for All Cities"
No selection (All visible)"All Cities" (Fallback)"Sales Performance for All Cities"

Functions Covered in this Chapter

Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:

Function 1

VALUES Function

Definition: Returns a one-column table of unique values visible in the current filter context, including the blank row if referential integrity is violated.

Syntax:
Visible Cities = VALUES(Dim_Store[City])
Parameters Breakdown:
  • TableNameOrColumnName: The column or table whose distinct visible rows are retrieved.
Real-World Example (Iterating Over Active Stores):
Problem / Scenario: How do you provide AVERAGEX with a list of currently filtered stores?
Formula: Store Avg = AVERAGEX(VALUES(Dim_Store[StoreID]), [Total Sales])
Result: Distinct list of active stores
Why it works: VALUES respects current slicer filters and provides a lightweight 1-column table for iterators.
Function 2

DISTINCT Function

Definition: Returns a one-column table containing unique values from a column, but strictly ignores the blank row introduced by referential integrity mismatches.

Syntax:
Strict Product Codes = DISTINCT(Dim_Product[ProductSKU])
Parameters Breakdown:
  • ColumnOrTable: The column or table expression from which duplicates are purged.
Real-World Example (Unique Active SKU Count):
Problem / Scenario: How do you return only real product SKUs excluding unmatched blank keys?
Formula: Valid SKUs = DISTINCT(Dim_Product[ProductSKU])
Result: Clean list of existing product SKUs
Why it works: DISTINCT omits the synthetic blank row that VertiPaq generates when fact records lack matching dimension keys.
Function 3

SELECTEDVALUE Function

Definition: Returns the value of a column when there is exactly one distinct value visible in the filter context; otherwise returns an alternate fallback result (or BLANK).

Syntax:
Selected Store = SELECTEDVALUE(Dim_Store[City], "All Cities")
Parameters Breakdown:
  • ColumnName: The column to inspect for single value selection.
  • AlternateResult: Optional fallback text or number returned when multiple or zero items are selected.
Real-World Example (Dynamic KPI Subtitle):
Problem / Scenario: How do you display "Viewing Mumbai Store" when Mumbai is chosen, or "All Stores" when none or multiple are chosen?
Formula: Card Subtitle = "Viewing: " & SELECTEDVALUE(Dim_Store[City], "All Stores")
Result: "Viewing: Mumbai"
Why it works: SELECTEDVALUE safely extracts single selections without crashing or throwing multi-value errors.

Common Mistakes & Limitations

  • Using `VALUES()` expecting a single scalar string without checking if multiple values exist, causing a "table of multiple values" error.
  • Using legacy `IF(HASONEVALUE(col), VALUES(col), "All")` when `SELECTEDVALUE(col, "All")` is 2x cleaner.

Keyboard Shortcuts

ActionWindowsMac
Create Title MeasureAlt -> Modeling -> New MeasureNew Measure
Bind Title to VisualVisual Format -> Title -> fx button -> Select Measurefx button

Pro Tips & Modern Alternatives

  • Use `SELECTEDVALUE` inside conditional measures to switch calculation logic based on a disconnected parameter table.
  • Use `DISTINCT()` when creating a standalone calculated table where you do not want an artificial blank row included.