Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
swatibehl
Microsoft Employee
Microsoft Employee

CALCULATE with removefilters

Hello,

I have requirement where in Card has to compute reliability as CalculateFailed/CalculateTotal .(Both Failed and Total are measures)

 

Slicer has below filters-

Errortype and Timestamp.

 

Calculate Failed Measure requires the Slicer filteration , however, CalculateTotal measure does not require the Errortype filter . 

I have create another measure to test the results with removefiters but it is not returning correct values

 

Slicer is build from  Table[ErrorType]

 

CalculateTotal Measure  = COUNTX(FILTER('Table', 'Table'[Operation]="Create"), 'Table'[ID])

 

CalculateFailed Measure = COUNTX(
    FILTER(
        'Table',
        'Table'[State] = "Failed" && Table[Operation] = "Create"),'Table'[Id])
 

Test Measure =

   VAR A =CALCULATE([CalculateTotal],REMOVEFILTERS(Table[ErrorType]))
        VAR B = CALCULATE([CalculateFailed],REMOVEFILTERS(Table[ErrorType]))
        RETURN A

 

VAR A is considering Errotype Slicer values passed from Slicer, not sure why is it so. Can anyone pleaase suggest

 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @swatibehl 

 

Based on your question, we guess that you may have an impact on filtering because you have table relationships.

 

In the method we provide, "all" only removes the filter of "error type" in the current table. If you have an “error type” in table B, there is a relationship between the two tables, and your slicer selects “error type” in table B, the same will have an impact.

vnuocmsft_0-1703670464246.png

vnuocmsft_1-1703670479621.png

vnuocmsft_2-1703670510118.png

 

You can try removing the "error type" to avoid the above reasons

vnuocmsft_3-1703670531430.png

 

Test Measure = 
    VAR TotalWithoutErrorType = CALCULATE([CalculateTotal], ALL('Table'))
    VAR FailedWithAllFilters = [CalculateFailed]
    RETURN TotalWithoutErrorType

 

 

Best Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @swatibehl 

 

Based on your question, we guess that you may have an impact on filtering because you have table relationships.

 

In the method we provide, "all" only removes the filter of "error type" in the current table. If you have an “error type” in table B, there is a relationship between the two tables, and your slicer selects “error type” in table B, the same will have an impact.

vnuocmsft_0-1703670464246.png

vnuocmsft_1-1703670479621.png

vnuocmsft_2-1703670510118.png

 

You can try removing the "error type" to avoid the above reasons

vnuocmsft_3-1703670531430.png

 

Test Measure = 
    VAR TotalWithoutErrorType = CALCULATE([CalculateTotal], ALL('Table'))
    VAR FailedWithAllFilters = [CalculateFailed]
    RETURN TotalWithoutErrorType

 

 

Best Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Anonymous
Not applicable

Hi @swatibehl 

 

You seem to want to calculate CalculateFailed/CalculateTotal, and CalculateTotal is not affected by slicers, here is the DAX we offer:

 

Here is the virtual table we created

vnuocmsft_0-1703553079804.png

 

The "CalculateTotal" and "CalculateFailed" measures you defined seem to be correct.

vnuocmsft_1-1703553108322.png

CalculateTotal = COUNTX(FILTER('Table', 'Table'[operation]="create"), 'Table'[id])

 

vnuocmsft_2-1703553146481.png

CalculateFailed = COUNTX(
    FILTER(
        'Table',
        'Table'[state] = "fail" && 'Table'[operation] = "create"),'Table'[id])

 

The modified Test Measure is as follows, and after the slicer is applied, Total is not affected

vnuocmsft_3-1703553182029.png

Test Measure = 
    VAR TotalWithoutErrorType = CALCULATE([CalculateTotal], ALL('Table'[error type]))
    VAR FailedWithAllFilters = [CalculateFailed]
    RETURN TotalWithoutErrorType

 

Create a measure to calculate reliability, here are the results

vnuocmsft_4-1703553219806.png

result = [CalculateFailed] / [Test Measure]

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Best Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Hello @Anonymous , thanks for taking time and helping .. 

I have tried the same details.. but when I  am returning Var for total wherein filter is not needed , is returning same result as that of applying filter. I am really going clueless why is this so

Var A returning 7 for Measure wherein slicer is not needed and is still in effect( even  though ALL is used)

swatibehl_0-1703567187428.png

 

Var B , for Failed measure is also returning same result with slicer is in effect and is good

swatibehl_1-1703567325690.png

 

 

 

Dangar332
Super User
Super User

HI, @swatibehl 

 

try below

CalculateTotal Measure  = 
   COUNTX(
      FILTER(
         all('Table'[errortype],'Table'[Operation],'Table'[ID]),
         'Table'[Operation]="Create"
      ),
      'Table'[ID]
   )

 

CalculateFailed Measure = 
   COUNTX(
       FILTER(
        all('Table'[errortype],'Table'[Operation],'Table'[ID],'Table'[State])
        'Table'[State] = "Failed" && Table[Operation] = "Create"
       ),
     'Table'[Id]
   )

swatibehl
Microsoft Employee
Microsoft Employee

thanks for your kind reply.. i have tried with suggested option , but no luck.do you have any running sample code ?

123abc
Community Champion
Community Champion

The issue you're experiencing is due to the way REMOVEFILTERS works in conjunction with the context of calculations in DAX. When you use REMOVEFILTERS(Table[ErrorType]), it removes the filters from the ErrorType column, but not from other columns or measures that may be affected by those filters.

Let's try to address your problem step by step.

  1. CalculateTotal Measure: Since this measure doesn't need the ErrorType filter, it remains as it is.

  2. CalculateFailed Measure: This measure needs to have the ErrorType filter removed when calculating. However, using REMOVEFILTERS as you've done may not work as expected because the context might still propagate from other parts of your model.

  3. Test Measure: You're trying to calculate the total and failed measures without the ErrorType filter.

A potential solution could involve using the ALLSELECTED function combined with your calculations. Here's how you can modify the Test Measure:

 

Test Measure =
VAR TotalWithoutErrorTypeFilter =
CALCULATE(
[CalculateTotal],
ALLSELECTED('Table'[ErrorType])
)

VAR FailedWithoutErrorTypeFilter =
CALCULATE(
[CalculateFailed],
ALLSELECTED('Table'[ErrorType])
)

RETURN
TotalWithoutErrorTypeFilter

 

Here, ALLSELECTED('Table'[ErrorType]) will remove the filter from ErrorType while retaining other filters (like the timestamp). This way, when you calculate your totals and failed counts, it will ignore the ErrorType filter but still respect other filters.

Ensure that you adjust the formula as per your model's specific requirements, but this approach should help you achieve the desired result.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.