ALLSELECTED DAX Function in Power BI

The ALLSELECTED function in Power BI (DAX) is used to modify the filter context by returning all the values in a table or column as if the visual-level filters were removed but still respects the filters coming from outside the visual (filter from slicers or filters).

DAX Syntax 1) ALLSELECTED(Table) It removes the visual filter context from the specified table. The Table parameter specifies the name of an existing table, using standard DAX syntax. This parameter cannot be an expression. 2) ALLSELECTED(ColumnName1[, ColumnName2[, ColumnName3[,…]]]] ) It remove the visual filter context from the specified columns. The parameter ColumnName specifies the name of an existing column using standard DAX syntax, usually fully qualified. It cannot be an expression. Please notes the columns must be from the same table. 3) ALLSELECTED() It removes all the visual filter context from the calculation.

Example: We have added a slicer with the Country field from Sheet1 table. Also, a table visual with the Country field and a measure “10th Marks Measure”.

The measure is calculated by the following DAX formula:

DAX

10th Marks Measure = SUM(Sheet1[10th Marks])

In the above DAX formula, we are summing the 10th Marks column of the Sheet1 table.

ALLSELECTED dax function in Power BI

As we know the measure is filtered on the visual levels also, so it is filtered automatically based on Country field added in the table visual.

Now let’s our requirement is to filter the measure on the external filter like slicers on the page but not by the visual level filter, then we can modify the measure calculation as shown below:

DAX

10th Marks Measure = CALCULATE(SUM(Sheet1[10th Marks]), ALLSELECTED())

The output of the above code is shown in the image below:

ALLSELECTED dax function in Power BI

Here, the measure value 6229 is the sum of Brazil, Canada, India, and Switzerland, but as we can see in the image.

Let’s add the Name column to the table, we can see our measure is not filtered even on the basis of name also from table.

ALLSELECTED dax function in Power BI

But for example, our requirement is to not filter the measure based on Country column, we want the measure to filter on the Name visual filter. To implement this, we can modify our measure formula, by specifying the column in the ALLSELECTED function from which we want to remove the filter.

DAX

10th Marks Measure = CALCULATE(SUM(Sheet1[10th Marks]), ALLSELECTED(Sheet1[Country]))

To see its effect lets use the matrix instead of table.

ALLSELECTED dax function in Power BI

We can see that the measure is not filtered based on country visual filter, but it is filtered on the basis of Name visual filter.

Please note that if the Name is repeated in the multiple countries, then that Name gives the sum from all the countries.

To demonstrate this, let’s use the following data:

ALLSELECTED dax function in Power BI

Now let’s remove the visual filter from the Country column of the table Sheet20.

DAX

ALLSELECTED Measure-II = CALCULATE(SUM(Sheet20[10th Marks]), ALLSELECTED(Sheet20[Country]))

The output of the above dax function is shown below:

ALLSELECTED dax function in Power BI

Specify Multiple Filters The ALLSELECTED function removes visual filters on Country column, but still the boolean filter reintroduces a filter condition that limits the calculation to Australia. All the filter expressions are ANDed to each other.

DAX

ALLSELECTED Measure With Filter = CALCULATE(SUM(Sheet1[10th Marks]),Sheet1[Country]= "Australia", ALLSELECTED(Sheet1[Country]))

The output of the above dax function is shown below:

ALLSELECTED dax function in Power BI

DAX

ALLSELECTED Measure With Filter = CALCULATE(Max(Sheet1[10th Marks]),Sheet1[10th Marks]= Max(Sheet1[10th Marks]), ALLSELECTED())

The output of the above dax function is shown below:

ALLSELECTED dax function in Power BI

Difference Between ALL, ALLSELECTED, and ALLEXCEPT Function

FunctionVisual FiltersSlicer FiltersPage/Report FiltersEffect
ALL(Sales)IgnoredIgnoredIgnoredRemoves all filters context from the table.
ALLSELECTED(Sales)IgnoredRespectedRespectedRemoves visual filters from the table.
ALLSELECTED(Sales[Product])Ignored (for Product)RespectedRespectedRemoves visual filters only for Product.
ALLEXCEPT(Sales, Sales[Product])Respected only for Product columnRespected only for Product columnRespected only for Product columnRemoves all filters context from the table except for the specified column.