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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
farhandsome
Helper I
Helper I

PBI Calculate Function - keep the contextual filters

Hi all,

 

I have a question about using the CALCULATE() function. 

 

I've made a measure using this function that I am using as part of a KPI card. However, that KPI card has filters on it. It seems that the measure I've created is ignoring those filters and only being parsed by the filters I've stated in CALCULATE(). How can I make it so that the value is filtered by both the CALCULATE function as well as the overarching context filters?

 

Thanks,

Farhan

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@farhandsome 

For the filter you use inside calculate function, wrap it in KEEPFILTERS, it will create and condition.
https://docs.microsoft.com/en-us/dax/keepfilters-function-dax
Example:

 

OnlyRed_KeepfiltersAll :=
CALCULATE (
    [Sales Amount],
    KEEPFILTERS (
        FILTER (
            ALL ( Products[Color] ),
            Products[Color] = "Red"
        )
    )
)

 

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@farhandsome 

For the filter you use inside calculate function, wrap it in KEEPFILTERS, it will create and condition.
https://docs.microsoft.com/en-us/dax/keepfilters-function-dax
Example:

 

OnlyRed_KeepfiltersAll :=
CALCULATE (
    [Sales Amount],
    KEEPFILTERS (
        FILTER (
            ALL ( Products[Color] ),
            Products[Color] = "Red"
        )
    )
)

 

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy ,

 

I see, so the "ALL(Products[Color])" is allowing the context filters to be passed through?

@farhandsome 

Yes, KEEPFILTERS will not overwrite, rather it adds to the existing filter and sort of itersects. 


________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@farhandsome 

Hope the explanation was clear? If so, accept the reply as a solution?

For further on this topic, refer to :https://www.sqlbi.com/articles/using-keepfilters-in-dax/


________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors