Dax Function: ALLEXCEPT

Category: Filter Functions

ALLEXCEPT is a Data Analysis Expressions (DAX) function in Power BI that removes filters from all columns in a table, except for those explicitly specified. It enables selective filtering, maintaining specific columns’ filter context while clearing others.

Purpose

The ALLEXCEPT function is used to:

  • Create measures that ignore most filters but honor specific ones.

  • Provide precise control over filter contexts in calculations.

  • Enable focused aggregations or comparisons by maintaining only relevant filters.

Type of Calculations

The function is often used for:

  • Dynamic aggregations.

  • Calculations requiring selective filter retention.

  • Percentage of total or subtotal calculations where some filters are preserved.

Practical Use Cases

  1. Selective Totals: Calculate totals based on specific filters while ignoring others.

  2. Dynamic Reporting: Enable drill-down reports by maintaining filter context for key dimensions.

  3. Custom Measures: Create measures that operate within specific filters.


ALLEXCEPT(<table>, <column1>, [<column2>, ...])</column2></column1></table>

ParameterTypeDescription
tableTableThe table containing the columns for which filters are cleared.
column1ColumnThe column for which filters are retained.
[column2, ...]Column(s)Additional columns for which filters are retained.

How Does ALLEXCEPT Dax Works

The ALLEXCEPT function:

  1. Removes all filters applied to a table.

  2. Retains filters on the specified columns.

  3. Evaluates expressions using the modified filter context.

Example Formula:

Selective Sales = CALCULATE( SUM(Sales[Amount]), ALLEXCEPT(Sales, Sales[Region]) )

Here, filters on Sales[Region] are retained, while others (e.g., date, product) are removed.

What Does It Return?

The function returns:

  • Table: A version of the input table where all filters are removed, except for the specified columns.

When Should We Use It?

  1. Selective Aggregations: When calculations need to respect filters on certain dimensions.

  2. Creating Measures: For percentage calculations where some filters need to remain active.

  3. Custom Visuals: Build visuals that respond only to specific filters.

Examples

Basic Usage :


ALLEXCEPT(Sales, Sales[Region])

Clears all filters on the Sales table, except for the Region column.

Column Usage


Region Sales =
CALCULATE(
SUM(Sales[Amount]),
ALLEXCEPT(Sales, Sales[Region])
)

Computes total sales while retaining region-specific filters.

Advanced Usage


Percentage of Region Sales =
DIVIDE(
SUM(Sales[Amount]),
CALCULATE(SUM(Sales[Amount]), ALLEXCEPT(Sales, Sales[Region]))
)

Calculates the percentage contribution of sales for each region to the total.

Tips and Tricks

  • Use for Drill-Down Reports: Maintain key filters while clearing unrelated ones for specific measures.

  • Combine with CALCULATE: Leverage CALCULATE to dynamically manage filter contexts.

  • Beware of Overuse: Applying too many exceptions can complicate the model and affect performance.

Performance Impact of ALLEXCEPT DAX Function:

  • Avoid using ALLEXCEPT on large tables with many exceptions, as this can lead to slow performance.

  • Optimize by targeting only necessary columns.

Related Functions You Might Need

  • ALL: Removes all filters from a table or column.

  • ALLSELECTED: Considers filters applied in a visual context.

  • REMOVEFILTERS: Explicitly removes filters from specified columns or tables.

Want to Learn More?
For more information, check out the official Microsoft documentation for ALLEXCEPT You can also experiment with this function in your Power BI reports to explore its capabilities.

Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.

1. What does the ALLEXCEPT function do in Power BI?

It removes filters from all columns in a table, except for the ones specified.

2. When should I use ALLEXCEPT?

Use it for calculations requiring selective filter retention, like drill-down aggregations.

3. How does ALLEXCEPT differ from ALL?

ALL removes all filters, while ALLEXCEPT retains filters for specified columns.

4. Can I use multiple columns in ALLEXCEPT?

Yes, you can specify multiple columns for which filters will be retained.

5. Is ALLEXCEPT resource-intensive?

It can be if applied to large datasets with many exceptions. Use it judiciously.