Forum Discussion

farhandsome's avatar
farhandsome
Icon for Helper I rankHelper I
6 years ago
Solved

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

  • 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

4 Replies

  • 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

    • farhandsome's avatar
      farhandsome
      Icon for Helper I rankHelper I

      Fowmy ,

       

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

      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

        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