Forum Discussion
filtering virtual tables
Hi George1970
The difference in the results between the two DAX expressions is due to the context in which the CALCULATETABLE function operates. Here’s a breakdown:
First Expression:
COUNTROWS(
FILTER(records, [Category] = "Other")
)
This expression directly filters the records table to include only rows where [Category] = "Other".
It then counts the number of rows in this filtered table, which correctly returns 5.
Second Expression:
COUNTROWS(
CALCULATETABLE(
records,
FILTER(records, [Category] = "Other")
)
)
CALCULATETABLE modifies the context in which the table is evaluated.
The Filter function inside CALCULATETABLE is applied to the entire records table, but CALCULATETABLE can introduce additional context that might affect the result.
If there are any existing filters or row contexts applied to records before this calculation,CALCULATETABLE might be including those contexts, leading to a different number of rows being counted.
To ensure both expressions return the same result, you can use the first approach or ensure that CALCULATETABLE is used in a context where no additional filters are affecting the result.
Best Regards,
Jayley
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks Jayley. I don't understand your point however. Doesn't
FILTER(records, [Category] = "Other")
modify the filter context of CALCULATETABLE so that CALCULATETABLE returns a table of 5 rows, which are then counted by COUNTROWS?