March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I have a Sample data Set and I tried to create another two filtered Tables A and Tables B with ALL and with same filtering conditions but A using FILTER and B using CALCULATETABLE.
Table A = FILTER(ALL(Data),Data[Region]="Central" && Data[Customer]="Andrews")
Table B = CALCULATETABLE(ALL(Data),Data[Region]="Central",Data[Customer]="Andrews")
FILTER's result was a filtered Table but CALCULATETABLE's result was a the complete Table without filtering.
I need to know what was the reason and what is the actual difference at practical level.
Solved! Go to Solution.
CALCULATETABLE is very handy to preserve all existing filters except for one or two modifications. For example, if trying to calculate something like % change of market share quarter over quarter for example. You can do something like:
VAR __tmpTable = SUMMARIZE( CALCULATETABLE('Table',ALL('Table'[Year]),ALL('Table'[Quarter]),ALL('Table'[Category])), [Category], [Year], [Quarter], "__Measure", [Market Share by Category Measure] )
You can use that as part of a measure calculation. The beauty of this approach is that this preserves any filters that you might have on other columns in that table.
Technically, CALCULATETABLE is a synonum for RELATEDTABLE.
The CALCULATETABLE function changes the context in which the data is filtered, and evaluates the expression in the new context that you specify. For each column used in a filter argument, any existing filters on that column are removed, and the filter used in the filter argument is applied instead.
Filter doesn't work that way, it uses a table expression and THEN applies filters.
Well, for some reason the DAX function reference seems to be offline or moved or something, but here would be my take.
The CALCULATETABLE function evaluates a table expression in a context modified by filters. So, the table expression in your formula is ALL(table). When you evaluate this with some filter, the evaluation is still ALL(). Effectively this ALL() trumps the filter because ALL is ALL, regardless of filters. ALL effectively removes any filters. So if you evaluate ALL in the context of ANY filter, it's still ALL. In other words, think of CALCULATETABLE as "evaluate this table expression with these filters applied".
FILTER works differently. Filter returns a table that has been modified by the specified filters. So, filter starts with a table and then applies filters to it versus the way CALCULATETABLE works, which is by taking the filters and applying them to a table expression.
An easy way to summarize this is to think of the steps involved:
CALCULATETABLE
FILTER
CALCULATETABLE is very handy to preserve all existing filters except for one or two modifications. For example, if trying to calculate something like % change of market share quarter over quarter for example. You can do something like:
VAR __tmpTable = SUMMARIZE( CALCULATETABLE('Table',ALL('Table'[Year]),ALL('Table'[Quarter]),ALL('Table'[Category])), [Category], [Year], [Quarter], "__Measure", [Market Share by Category Measure] )
You can use that as part of a measure calculation. The beauty of this approach is that this preserves any filters that you might have on other columns in that table.
Technically, CALCULATETABLE is a synonum for RELATEDTABLE.
The CALCULATETABLE function changes the context in which the data is filtered, and evaluates the expression in the new context that you specify. For each column used in a filter argument, any existing filters on that column are removed, and the filter used in the filter argument is applied instead.
Filter doesn't work that way, it uses a table expression and THEN applies filters.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
125 | |
85 | |
69 | |
54 | |
45 |
User | Count |
---|---|
204 | |
106 | |
98 | |
65 | |
54 |