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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
michellepace
Resolver III
Resolver III

Must I explicitly use "filter( )" when using CALCULATE?

Hello,

The two dax expressions below yield the same results. If I do not explicitly state "filter" when I am using calculate, will I eventually get myself into trouble? 

 

Do I have to explicitly say FILTER when using CALCULATE.png

1 ACCEPTED SOLUTION

Thank you both for your replies of which I have worked through. Going forward, when using CALCULATE I will always default to explicitly using FILTER( )

 

For anyone else interested in why to do this, have a look at the screenshot below. Shortly after posting here the course which I'm currently working through addressed my question too.

 

Always_use_filter_in_CALCULATE.png

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@michellepace , to overserve the difference; try this

have only one filter

[product name] = "Product 2" and check it this measure with axis/row/group as the product name.  Same filter same axis , try both option in different visual

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you both for your replies of which I have worked through. Going forward, when using CALCULATE I will always default to explicitly using FILTER( )

 

For anyone else interested in why to do this, have a look at the screenshot below. Shortly after posting here the course which I'm currently working through addressed my question too.

 

Always_use_filter_in_CALCULATE.png

@michellepace  Products[Product Name] = "Product 100" internally expand to the below version and for each row of the matrix the same condition is evaluated, as presence of ALL removes any filter coming to Product Name from the report and that's why you get the same value for each cell

=
CALCULATE ( [Total Sales], Products[Product Name] = "Product 100" )

--version above is equivalent to the below

=
CALCULATE (
    [Total Sales],
    FILTER (
        ALL ( Products[Product Name] ),
        Products[Product Name] = "Product 100"
    )
)

 If you want to get the same result as with using FILTER then use KEEPFILTERS this way there will be a Set intersection operation, i.e. if Product 100 is currently in the filter context then only will it return something otherwise you will get blank

https://en.wikipedia.org/wiki/Intersection_(set_theory)

=
CALCULATE (
    [Total Sales],
    KEEPFILTERS ( Products[Product Name] = "Product 100" )
)

-- version above is similar to the below one:

=
CALCULATE (
    [Total Sales],
    KEEPFILTERS (
        FILTER (
            ALL ( Products[Product Name] ),
            Products[Product Name] = "Product 100"
        )
    )
)

 

The problem with the below one is that you are referring to the expanded products table, and in case of Snow flake schema you would see unexpected result, for star schema it should be fine as Products expands to itself (assuming)  

https://www.sqlbi.com/articles/expanded-tables-in-dax/

 

Another problem is that you are applying all the columns of the Products table to the filter context to evaluate Total Sales, while you can already do this with a single column, that way you have a more efficient formula

=
CALCULATE (
    [Total Sales],
    FILTER ( Products, Products[Product Name] = "Product 100" )
)

 

harshnathani
Community Champion
Community Champion

Hi @michellepace ,

 

Please see this video for the difference between FILTER and FILTER (ALL(....) )

 

https://www.youtube.com/watch?v=bJtRB86n9tk

 

The first 30 minutes is interesting to understand the differences,

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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