Sub topic 3
Putting It Together: Percent of Total and Percent of Group
Assume you know basic DAX measures, tables, relationships, and how slicers and visuals filter a model. The key idea is that a measure reads the current filter context unless CALCULATE changes it.
Total Sales = SUM ( Sales[Amount] )
Sales % of All Products =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product' ) )
)
Sales % of Category =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
ALLEXCEPT ( 'Product', 'Product'[Category] )
)
)In a visual grouped by product, the first measure keeps the current product in the numerator but removes product filters in the denominator. The result is each product's share of all product sales. Date, customer, and other filters remain active.
The second measure removes product filters except Category. It therefore compares each product with the total for its current category.
> callout note > Use DIVIDE instead of /. It safely handles a blank or zero denominator.
Choosing the Function
- Use a boolean
CALCULATEfilter for a simple column condition. - Use
FILTERwhen the condition needs several columns, row-by-row logic, or a measure. - Use
REMOVEFILTERSwhen the intent is only to clear filters. - Use
ALLwhen you need a table or column of values, or when clearing filters insideCALCULATE. - Use
ALLEXCEPTwhen all filters on a table should disappear except selected columns.
Common Pitfalls and Performance
REMOVEFILTERS clears filters but does not return a table expression. Do not write COUNTROWS ( REMOVEFILTERS ( 'Product' ) ). Use ALL ( 'Product' ) when a table is required.
Prefer filtering a column instead of a whole table when possible. Large FILTER iterations can be slower and may produce unexpected results if relationships or context are misunderstood.
Where to Go Next
ALLSELECTED supports visual totals while respecting outer selections. KEEPFILTERS adds a condition without replacing an existing column filter. VALUES returns the distinct values visible in the current context.
Exercise
Which function makes a product's denominator keep Category but remove other Product filters?
Show answer
ALLEXCEPT ( 'Product', 'Product'[Category] ).