Forum Discussion

Cyriackpazhe's avatar
Cyriackpazhe
Icon for Helper III rankHelper III
1 year ago
Solved

table as calculate argument

Can someone explain how a table expression is applied as filter argument in calculate.  a virtual table based on the filter condition is created , then the expression is evaluated  
  • bhanu_gautam's avatar
    1 year ago

    Cyriackpazhe 

    Table Expression as Filter
    When you use a table expression as a filter argument in the CALCULATE function, DAX creates a virtual table based on the filter condition specified in the table expression. This virtual table is then used to modify the filter context of the calculation.

     

    Example
    Consider the following DAX expression:

     

    TotalSalesFiltered = CALCULATE(
    [TotalSales],


    FILTER(
    Sales,
    Sales[Region] = "North"
    )
    )


    In this example:

    [TotalSales] is the measure or expression that calculates the total sales.
    FILTER(Sales, Sales[Region] = "North") is the table expression used as a filter argument. This expression creates a virtual table that includes only the rows from the Sales table where the Region column has the value "North".


    How It Works
    Creating the Virtual Table: The FILTER function generates a virtual table that contains only the rows from the Sales table where the Region is "North".
    Modifying the Context: This virtual table is then used to modify the filter context of the CALCULATE function. Essentially, it tells CALCULATE to consider only the rows in this virtual table for the calculation.
    Evaluating the Expression: Finally, the [TotalSales] measure is evaluated in this new filter context, which includes only the rows where the Region is "North".