Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hey there Power-BI community!
I have a general question regarding the use of calculated tables inside a measure defintion which arose as i was playing with the example-dataset in Power-BI-Desktop. The data-model consists of a fact-table called 'financials' and a date-table called 'Calendar'. They are linked via a 1:*-relationship on the date-columns.
The calender-table 'Calendar' itself is a calculated table which was created as follows:
Calendar =
VAR cal= CALENDARAUTO()
VAR res = ADDCOLUMNS(
cal,
"Year",
YEAR([Date]),
"Month Number",
MONTH([Date])
)
RETURN res
Just for testing my understanding i created the following measure [Sales of October]:
Sales of October =
VAR summarizedTable = SUMMARIZE(
'financials',
'Calendar'[Month Number],
"Sum of Sales",
SUM(financials[ Sales])
)
VAR result = CALCULATE(
SUMX(
summarizedTable,
[Sum of Sales]
),
FILTER(
summarizedTable,
[Month Number] = 10
)
)
RETURN result
Calculating the measure [Sales of October] against the Calendar'Month Number' column gives the following result:
The measure can be described as follows:
However the result is that for each month in the visual the corresponding sum of sales for the specific month gets calulated. It seems as if the filter-context hasn't been changed through the use of CALCULATE at all.
However if i create the summarized-table as a calculated table outside of the measure-definition, and the measure references this calculated-table, then the correct result gets computed:
Definition of the calculated table 'Table with Sales by Month':
Table with Sales by Month =
SUMMARIZE(
'financials',
'Calendar'[Month Number],
"Sum of Sales",
SUM(financials[ Sales])
)
Measure definition [Sales of October with calculated table outside of the measure defintion]:
Sales of October with calculated table outside of the measure definition = VAR result = CALCULATE( SUMX( 'Table with Sales by Month', [Sum of Sales] ), FILTER( 'Table with Sales by Month', [Month Number] = 10 ) ) RETURN result
Result:
Note: The measure computes the Sum of Sales for the month october regardless of the row in the visual, since when 'Table with Sales by Month' was created there was no filter-context present. Thus when changing the filter-context by the use of CALCULATE the sum of Sales for october gets calculated regardless of the current row/filter-context in the visual.
My general question is: why does CALCULATE change the filter context when the calculated table has been created outside of the measure-definition, but it doesn't change the filter-context when it has been created inside the measure-definition.
This is just a theoretical question and i was wondering if someone might help me sharpening my understanding.
PS: this is my first post, so i apologize in advance if my question is not properly formated. Thanks in advance for your kind replies!
Kind regards,
Freddy
Hi! These articles from Marco Russo and Alberto Ferrari at SQLBI may help to clear things up: Introducing DEFINE COLUMN in DAX queries - SQLBI and Introducing DEFINE TABLE in DAX queries - SQLBI
Proud to be a Super User! | |