Forum Discussion

Sania-F's avatar
Sania-F
Icon for Resolver I rankResolver I
11 months ago
Solved

Filter Context - Importance of HASONEVALUE with VALUES function

Error - a table of multiple VALUES was supplied when single value was expected.   dax -  sales commission = [Revenue]* IF(VALUES('Sales Territory'[Country]) = "United States", 0.15,0.1)    ...
  • tayloramy's avatar
    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.