Forum Discussion
Filter Context - Importance of HASONEVALUE with VALUES function
- 11 months ago
Hi Sania-F,
You’re seeing that error because VALUES('Sales Territory'[Country]) returns a table of distinct countries in the current filter context. When there’s more than one country in scope (totals, multi-select slicers, unfiltered visuals, etc.), comparing that table to the string "United States" makes DAX throw “a table of multiple values was supplied…”. HASONEVALUE() suppresses the error by short-circuiting when there isn’t exactly one country-but it also returns blank in those cases, which often gives wrong totals.
Use SELECTEDVALUE and aggregate per country with SUMX so totals add up:
Sales Commission := SUMX( VALUES('Sales Territory'[Country]), [Revenue] * IF( SELECTEDVALUE('Sales Territory'[Country]) = "United States", 0.15, 0.10 ) )If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
VALUES('Sales Territory'[Country]) returns a table and you cannot compare a table to a value like "United States"
HASONEVALUE checks that VALUES returns a single value (a table of one row and one column) and in that case DAX turrns that table (of one row and one column) into a single value so it works
If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI