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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.