← All challenges

D3 · DAX · DAX basics · about 10 min

Selected Season Label

easy

The report title card should say which season is on screen. It works until someone selects both seasons in the slicer: then the card shows an error, and on the overview page with no slicer it errors too.

Your task

Create a measure named [Season Label] that returns the text "Season 2024" (or 2025) when exactly one season is in the filter, and "All seasons" otherwise. Use those exact words.

What the grader checks

You see the situations, not the expected numbers. The expected values are computed live from your file and the source data.

  • T1One season selected
    Season slicer set to 2024.
  • T2Both seasons selected
    Season slicer with 2024 and 2025 both ticked.
  • T3No slicer
    A page with no season filter at all.
  • T4One row per season
    A table with one row per season.

Stuck?

Open one hint at a time.

Hint 1

What does a filter on Season contain when two seasons are ticked, or when there is no slicer? How many values is that?

Hint 2

VALUES returns a table. It can be used as a single value only when it has exactly one row; otherwise you get an error. There is a function that returns the one value, or blank when there are several.

Hint 3 (near-answer)

SELECTEDVALUE( Games[Season] ) returns the season when exactly one is selected and blank otherwise. Test for blank and return "All seasons" in that case.

Show the editorial

Solve it first if you can: the editorial gives the answer away.

The trap

"Season " & VALUES( Games[Season] ) works while exactly one season is selected, so it passes every check you do with the slicer set. With two seasons, or none, VALUES returns two rows and the measure errors. MAX avoids the error but quietly labels a two-season page "Season 2025", and SELECTEDVALUE with no fallback shows a half-finished "Season ".

The fix

VAR s = SELECTEDVALUE( Games[Season] ) RETURN IF( ISBLANK( s ), "All seasons", "Season " & s ). Or IF( HASONEVALUE( Games[Season] ), ..., "All seasons" ).

Why it works

A slicer is a filter, and a filter can hold one value, many, or none. Code that needs a single value has to ask whether there is one: SELECTEDVALUE does that and returns blank when the answer is no, which you then turn into the label for the other cases.

Every measure that reads "the selected" value must say what happens when zero or several are selected.