Calculation of total sales by category regardless of the selected country

If we have a [Total sales] measure that sums the sales amounts, we can display sales by category by taking the field containing the list of categories, ProductCategory[Category], into a table along with the [Total sales] measure:

Sales by category

If we add a segmentation containing the list of countries and select one, we see how our table is filtered properly:

Sales by category in Australia

If we wanted to calculate the total sales by category, regardless of the country or countries that have been selected, we could do so by making sure that the calculation is done for the entire list of countries, that is, cleaning the Geography table of filters (also we could clean up the filters applied to the field of the Geography table containing the list of countries, although in this case the numbers returned by the measure might change if a filter is applied to some other field in the table). To "clean" the Geography table of filters we will use the ALL function, and to recalculate the [Total sales] measure in the new context we will use the CALCULATE function:

Category sales =

    CALCULATE(

    SUM(Sales[SalesAmount]),

    ALL(Geography)

)

The result, if we take the new measure to the table that we had created, is the following:

Sales by category for all countries
DAX functions involved
Difficulty
Low
Submitted by admin on Sat, 01/12/2019 - 18:14