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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jnickell
Helper V
Helper V

Unexplained filter in Calculate - Countrows

I am probably overlooking something very basic here, so I beg your mercy.  

 

I am trying to write a measure against a single table. There are other tables in the model, but in the measure and on the page I am only using columns and values from this single table. 

 

My issue is that if I include a filter on one of the date columns in the table, the measure does not calculate as I would expect. If I remove the date filter, the measure calculates as I expect.  There is a Date table and it is linked to this table on a different date value, but that date value and the Date table are not being referenced on the page or in the measure.

 

__ Vendor % of Total (Count) = 
// Percentage of the number of orders measured
    VAR TotalOrdersByVendor = 
        CALCULATE(
            COUNTROWS('Purchase Orders'),
            //REMOVEFILTERS('Purchase Orders'[On Time Status]  'Purchase Orders'[Date Entered]) // this works
            REMOVEFILTERS('Purchase Orders'[On Time Status]) // this does not work
        )
    VAR OrdersOfXStatus = 
        CALCULATE(
            COUNTROWS(
                'Purchase Orders'
            )
        )
    Return 

        "L: " & OrdersOfXStatus & " T: " & TotalOrdersByVendor

 

I am trying to produce a measure that I can apply a visual/page filter to display the filter's % of total Purchase Orders for the time in question. Specifically by Vendor for PO's entered in the past year how many of them are closed and late. The example measure doesn't have the Remove Filter for "Closed" status because I was trying to track down what was breaking the measure.
If I remove the date entered filter (the Calculate parameter that's commented out), I get the values I expect. I'm unable to figure out what the filter criteria is evaluating to if I allow a filter on the Date Entered.

 

Sample Data is included.https://azahner.box.com/s/m9ytbwoal9jcsb23zh6jlwp32aclhl2m 

 

Thank you for your help!

1 ACCEPTED SOLUTION
jnickell
Helper V
Helper V

I did some more research and where it looks like this often happens due to Sort-By, I'm not using Sort-By on the table in question. 

I found this that I believe is probably the correct culprit. 

https://stackoverflow.com/questions/68070004/removefilter-all-dax-not-working-as-expected-power-bi-d... where they references SQL BI article for Auto-Exist.  

Since I'm trying to filter on multiple columns on the same table I think it's accurate.

https://www.sqlbi.com/articles/understanding-dax-auto-exist/

 

Now I need to adjust my model or the measure.

View solution in original post

3 REPLIES 3
jnickell
Helper V
Helper V

I did some more research and where it looks like this often happens due to Sort-By, I'm not using Sort-By on the table in question. 

I found this that I believe is probably the correct culprit. 

https://stackoverflow.com/questions/68070004/removefilter-all-dax-not-working-as-expected-power-bi-d... where they references SQL BI article for Auto-Exist.  

Since I'm trying to filter on multiple columns on the same table I think it's accurate.

https://www.sqlbi.com/articles/understanding-dax-auto-exist/

 

Now I need to adjust my model or the measure.

v-zhangti
Community Support
Community Support

Hi, @jnickell 

 

You can try the following methods.

Measure = 
Var _Total=CALCULATE(COUNT('Table'[PO Number]),ALL('Table'))
Var _status=CALCULATE(COUNT('Table'[PO Number]),ALLEXCEPT('Table','Table'[On time status]))
Return
DIVIDE(_status,_Total)

vzhangti_0-1679550599792.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

I apologize for the delay in responding, but no, that does not work because it removes "ALL" context filters on the Purchase Orders table, when I want to retain the Vendor filter.

 

I'm only evaluating the percentage based for that vendor.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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