Power BI

Use ALLSELECTED() in Power BI to Fix Incorrect Total Calculations

How to Use ALLSELECTED() in Power BI to Fix Incorrect Total Calculations

Table of Contents

Introduction

When working with Microsoft Power BI, it is crucial to understand how filters affect your calculations, like ALLSELECTED(). The ALL() and REMOVEFILTERS() functions are some of the most used functions for handling filter contexts. However, these functions do not always work as expected, especially when working with slicers.

If you’re new to how ALL() works, you can first explore this guide: Using ALL() to Ignore Filters, which explains how filters can be removed in calculations. The ALL() function typically ignores filters and returns all data, acting like a reset for filter context.

In this blog, you will work with a real-world problem where these two functions do not work as expected. Additionally, you will learn how to use the ALLSELECTED() function to create better and more dynamic measures.

Using ALLSELECTED()

In this section, you will learn when functions like ALL() and how to create robust measures.

To understand this concept:

  1. Download and open the Power BI file (ALLSELECTED.pbix) from the link provided below the blog and follow the step-by-step instructions to practice. 
  2. Click on Slicer in the Visualization Pane.
  3. Drag and drop Group from SalesTerritoty to the Field.
  4. Now, click on Europe.
  5. Click on Matrix in the Visualization pane.
  6. Drag and drop Country from the Sales Territory table into the Rows field.
  7. Drag and drop Total Sales Amount (CM) from the All Measures table into the Values field.
  8. Resize the matrix visual if required for better visibility.
Total sale Amount Table
Figure 1: Notice here is that % of Total Sales (CM) shows a value of 18.03%, which is equal to the total. The reason for this is that the Total Sales Amount (CM), the source measure behind the percent calculation, has a REMOVEFILTERS function in its definition coming from the All Sales (CM).
Figure 2 Adding the ALLSELECTED() function corrects the percentage calculation error.

Observe that the percentage numbers are being influenced by the selection of the slicer. Instead of computing the percentage with respect to the total sales figure, the percentage will now be computed with regard to the selected region alone (which is Europe, in this case). In this manner, the total shows a value of 18.03%, rather than 100%.

 In order to compute percentages with respect to selected data while maintaining the correct totals, the use of ALLSELECTED() can prove helpful.

To see how ALLSELECTED() helps solve this problem: 

  9. Right click on All Measures in the Fields.

  10. Click on New measure.

       Measure tools open.

  11. Type the following formula in the formula bar and press Enter.

formula bar
Figure 3: DAX measure using ALLSELECTED() to calculate total sales based on slicer selections while ignoring row-level filters in the matrix visual.

     You do not need to format this measure because it is an intermediate measure.

     Let’s use this measure to find the percentage of sales.

   12. Right click on All Measures in the Fields.

   13. Click on New measure.

        Measure tools open.

   14.Type the following formula in the formula bar and press Enter.

Figure 4: DAX measure showing percentage of total sales using the ALLSELECTED function.

 15. Click on the “%” in the formatting section.

 16. Drag and drop ALL Selected Country Sales (CM) and % of Total Sales using ALLSELECTED (CM) from the All Measures table to the Values.

ALLSELECTED Table
Figure 5: Notice that the % of Total Sales using ALLSELECTED (CM) has a value of 100% when nothing is selected in the slicer.

 17. Now, click on Europe.

ALLSELECTED Table
Figure 6: Notice that after selecting Europe, you still have 100% as the total value and contribution from each country in the group has been recalculated.

Conclusion

From this blog, you have learned how functions can sometimes not respect what the slicers have chosen, which can lead to incorrect totals. Using ALLSELECTED() inPower BI, however, can help ensure that your measures respect what the user has chosen, while still maintaining the correct percentages.

This will help you design more interactive and accurate reports in Power BI, especially when working with slicers. It is essential to master these concepts to help you design more robust and user-friendly reports.

FAQs

ALLSELECTED() is a DAX function that returns all rows in a table while keeping filters applied by slicers and user selections.

ALL() removes all filters completely, whereas ALLSELECTED() retains filters applied through slicers and visuals, making it more suitable for interactive reports.

Because ALL() ignores slicer filters, it calculates totals based on the entire dataset instead of the selected subset.

Extended Learning & References     

For more in-depth learning and advanced Power BI training, enrol in    

Here, you can access detailed courses and resources designed to enhance your Power BI skills and take your reporting capabilities to the next level.   

 

Leave a Reply

Your email address will not be published. Required fields are marked *