This past week in the Data School, we've been revisiting writing DAX in PowerBI, which has been fun to get stuck back in to query languages to keep my knowledge fresh and to continue the learning process.
We learnt a few new query functions, of which, two really had me stumped when trying to get an end result. Those two functions were SELECTEDVALUE and VALUES. I was using VALUES, when I should've been using SELECTEDVALUE, BUT, in this very specific case, VALUES actually worked!
After finding out I should've been using SELECTEDVALUES, explained by my coach, I thought it would be interesting to consolidate my learning and understanding by summarising the main differences between the two functions and best use case scenarios...
1. What?
- In DAX, both SELECTEDVALUES and VALUES are used to return values from a column.
- SELECTEDVALUES(column, [alternate result]) returns a single value from a column if only one value is selected.
- If no value or more than one value exists, it returns:
- BLANK by default, or
- The value you specify as an alternate result
- If no value or more than one value exists, it returns:
- VALUES(column) returns a distinct list of values in the specified column.
- If more than one value exists, it returns a table of those values.
- If no values exist, it returns an empty table.
- If one value exists, you can wrap it with aggregation or iteration.
- If more than one value exists, it returns a table of those values.
- When?
- Let’s say you’re working with a Customer[Country] column in a slicer and you want to return all of the selected countries, you would write;
- CountryList = VALUES(Customer[Country])
- This returns a table of all selected countries.
- Using the same example:
- SelectedCountry = SELECTEDVALUES(Customer[Country], "Multiple or None")
- This returns the single selected country (like "France")
- Why?
- Use VALUES() when you need to iterate through multiple values, or feed them into table-based functions
- like FILTER or CALCULATETABLE
- Great for returning a list of distinct values
- Use SELECTEDVALUES when you're referencing slicers or fields where only one value is expected or desired
- Example: in dynamic titles, KPIs, or conditional logic.
- Safer for returning a single value, with a custom fallback
Hope you found this helpful.
