Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Direct Query and using CalculateTable

I'm confused.   I thought a direct query model would not allow the DAX creation of a table using CALCULATETABLE.   I created a formula using that function in the fomula below, in a direct query model, with no problem.   Am I understanding the documentation correctly?    

 

  • Calculated tables aren't supported: The ability to define a calculated table using a DAX expression isn't supported in DirectQuery mode.

 

PYTD Net Shipped Revenue =
IF (
[ShowValueForDates],
CALCULATE (
[YTD Net Shipped Revenue],
CALCULATETABLE (
DATEADD ( 'Dim_Date Table'[Date], -1, YEAR ),
'Dim_Date Table'[DatesWithShipDates]
)
))
1 ACCEPTED SOLUTION

Hi @Anonymous 

 

It's an interesting question I have never thought about. I read some official documents again and found below descriptions. 

 

Calculated tables are recalculated if any of the tables they pull data from are refreshed or updated, unless the table uses data from a table that uses DirectQuery; in the case with DirectQuery, the table will only reflect the changes once the dataset has been refreshed. If a table needs to use DirectQuery, it's best to have the calculated table in DirectQuery as well. (From Using calculated tables in Power BI Desktop - Power BI | Microsoft Docs)

 

You can add calculated tables to a model that uses DirectQuery. The Data Analysis Expressions (DAX) that define the calculated table can reference either imported or DirectQuery tables or a combination of the two.

Calculated tables are always imported, and their data is refreshed when you refresh the tables. If a calculated table refers to a DirectQuery table, visuals that refer to the DirectQuery table always show the latest values in the underlying source. Alternatively, visuals that refer to the calculated table show the values at the time when the calculated table was last refreshed. (From Use composite models in Power BI Desktop - Power BI | Microsoft Docs)

 

It seems you are using CALCULATETABLE in a measure. If you put this measure in a visual, I think it will always query the latest data from the data source and do a calculation on that. When we say the calculated table, it refers to a table created using the New table feature under Modeling rather than the CALCULATETABLE function in DAX. A calculated table refers to a table defined by a DAX formula. 

081103.jpg

 

Hope this can help make it clear. 

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , I am not fine with complete statement

 

But you can try like

 

PYTD Net Shipped Revenue =
IF (
[ShowValueForDates],
CALCULATE (
[YTD Net Shipped Revenue],
DATEADD ( 'Dim_Date Table'[Date], -1, YEAR )
))

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak   Thanks.   I was more asking about the ability of Direct Query to handle the CALCULATETABLE function.    The Microsoft documentation seems to suggest that direct query model cannot support this functionality, but I am using it with no probem.   So that is where it seems confusing.  

Hi @Anonymous 

 

It's an interesting question I have never thought about. I read some official documents again and found below descriptions. 

 

Calculated tables are recalculated if any of the tables they pull data from are refreshed or updated, unless the table uses data from a table that uses DirectQuery; in the case with DirectQuery, the table will only reflect the changes once the dataset has been refreshed. If a table needs to use DirectQuery, it's best to have the calculated table in DirectQuery as well. (From Using calculated tables in Power BI Desktop - Power BI | Microsoft Docs)

 

You can add calculated tables to a model that uses DirectQuery. The Data Analysis Expressions (DAX) that define the calculated table can reference either imported or DirectQuery tables or a combination of the two.

Calculated tables are always imported, and their data is refreshed when you refresh the tables. If a calculated table refers to a DirectQuery table, visuals that refer to the DirectQuery table always show the latest values in the underlying source. Alternatively, visuals that refer to the calculated table show the values at the time when the calculated table was last refreshed. (From Use composite models in Power BI Desktop - Power BI | Microsoft Docs)

 

It seems you are using CALCULATETABLE in a measure. If you put this measure in a visual, I think it will always query the latest data from the data source and do a calculation on that. When we say the calculated table, it refers to a table created using the New table feature under Modeling rather than the CALCULATETABLE function in DAX. A calculated table refers to a table defined by a DAX formula. 

081103.jpg

 

Hope this can help make it clear. 

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

really helpful knowledge! Save my day and thanks for sharing

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.