Cumulative Period Aggregations: TOTALYTD, TOTALQTD & TOTALMTD
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 Selection | SELECTEDVALUE() Result | Visual 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:
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.
Visible Cities = VALUES(Dim_Store[City])
TableNameOrColumnName: The column or table whose distinct visible rows are retrieved.
Store Avg = AVERAGEX(VALUES(Dim_Store[StoreID]), [Total Sales])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.
Strict Product Codes = DISTINCT(Dim_Product[ProductSKU])
ColumnOrTable: The column or table expression from which duplicates are purged.
Valid SKUs = DISTINCT(Dim_Product[ProductSKU])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).
Selected Store = SELECTEDVALUE(Dim_Store[City], "All Cities")
ColumnName: The column to inspect for single value selection.AlternateResult: Optional fallback text or number returned when multiple or zero items are selected.
Card Subtitle = "Viewing: " & SELECTEDVALUE(Dim_Store[City], "All Stores")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
| Action | Windows | Mac |
|---|---|---|
| Create Title Measure | Alt -> Modeling -> New Measure | New Measure |
| Bind Title to Visual | Visual Format -> Title -> fx button -> Select Measure | fx 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.