I've got a data table, "DF", with two columns: "Country" and "Sales". I've been trying to create a measure that would display a treemap (or a pie chart, for that matter) where, upon selecting one or more categorical values from a slicer (in this case, Germany), all but said selected values would be aggregated into one category ("Others") with same colour as follows:
Unfortunately, my DAX skills are not as sharp as I would want them to be. I figured the appropiate logic would be to first create the following VARs:
VAR SelectedCountries = VALUES('DF'[Country])
VAR Sales_SelectedCountries =
CALCULATE(
SUM('DF'[Sales]),
'DF'[Country] IN SelectedCountries
)
VAR Sales_OtherCountries =
CALCULATE(
SUM('DF'[Sales]),
NOT('DF'[Country] IN SelectedCountries)
)
Now I guess all that's left is introducing RETURN and create a custom table where I'd add Sales_SelectedCountries and Sales_OtherCountries as columns under the appropiate lable and colour, and put them in the visual; but I can't seem to figure out the logic behind the next segment of code.


You can create a new table with two columns. If a country is selected in the slicer, it will appear with its actual name and sales; all unselected countries will be aggregated into one row labeled "Others" :