Forum Discussion

mrsja2024's avatar
mrsja2024
Regular Visitor
2 years ago
Solved

CALCULATE With FILTER or Without Which is BETTER ?

These two formulas lead to the same results
Which one is better to use ?
-----------------------------------
Formula 1:

Sales in europe = CALCULATE(SUM(Sales[Cost]),
                            'Region'[Group]="europe",
                            'Region'[SalesTerritoryKey]=10)
-----------------------------------
Formula 2:
Sales in europe2 = CALCULATE(SUM(Sales[Cost]),
                             FILTER(Region,'Region'[Group]="europe"),
                             FILTER('Region','Region'[SalesTerritoryKey]=10)
                            )

 

  • mrsja2024 Formula 1 is better approach but if the result should be same as Formula 2 in EVERY situation then you need to include KEEPFILTERS as well, right now it is working because you're not using Group & SalesTerritoryKey columns in the report.

    Sales in europe =
    CALCULATE (
        SUM ( Sales[Cost] ),
        KEEPFILTERS ( 'Region'[Group] = "europe" ),
        KEEPFILTERS ( 'Region'[SalesTerritoryKey] = 10 )
    )

    It is a best practice to filter only columns and not the whole table.

     

    Use FILTER when you bring columns from different tables and have to filter out some combinations. 

2 Replies

  • AntrikshSharma's avatar
    AntrikshSharma
    Icon for Community Champion rankCommunity Champion

    mrsja2024 Formula 1 is better approach but if the result should be same as Formula 2 in EVERY situation then you need to include KEEPFILTERS as well, right now it is working because you're not using Group & SalesTerritoryKey columns in the report.

    Sales in europe =
    CALCULATE (
        SUM ( Sales[Cost] ),
        KEEPFILTERS ( 'Region'[Group] = "europe" ),
        KEEPFILTERS ( 'Region'[SalesTerritoryKey] = 10 )
    )

    It is a best practice to filter only columns and not the whole table.

     

    Use FILTER when you bring columns from different tables and have to filter out some combinations. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    These three pics are self explanatory for when, where and how to use filter function.