Forum Discussion
table as calculate argument
- 1 year ago
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".
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".
So suppose I write an express calcalute( countrows(regions), filter(sales, sales [qty] >300)) how does that filter argument (table) used to evaluate the expression. In this case, "regions" table is part of the expanded table of sales. Could you explain how the table as filter argument used as filter context to evaluate the expression.