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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Regex
Regular Visitor

Is it possible to refer to the SAME temporary variable Table in TWO different measures?

Hi,

 

I have 2 measures measure_1 and measure_2. Both utilize the exact same temporary variable table TempTable to calculate the final result. The calculation of TempTable is very heavy and depends on the filter context. Thus the exact same calculation is done TWICE, and it would make sense to reuse TempTable instead.

 

Is it possible to reduce total calculation time by 50% by e.g.

  1. In measure_2, can we somehow refer to VAR TempTable already calculated in measure_1 ?
  2. Or, can we generate TempTable on-the-fly as a calculated table inside the Data Model, and then refer to it from both measure_1 and measure_2 ?
  3. Any other ideas?

I'm using PowerPivot, but i'm also interested if it is possible in Power BI.

 

Thanks!

5 REPLIES 5
AntrikshSharma
Community Champion
Community Champion

Nope variables are local to the measure they are defined in are not available globally, if you could just post the code here we could still try to understand how to optimize it.

Thanks Antriksh, but I already spent several days optimizing the code with Dax Studio.

 

This is a huge weakness in DAX compared to an SQL stored procedure.

 

I have an idea for a partial workaround though in PowerPivot/Excel. 

 

Step 1: EVALUATE the DAX code of TempTable in a worksheet connection in Excel.

Step 2: Query TempTable into the datamodel

Step 3: Calculate measure_1 and measure2

 

Subsequent problems

  • EVALUATE can't see the filter context of the data model?
  • User has to trigger the query?

EVALUATE is just a syntax to run the code and nothing else. What you define on rows and columns would be a part of SUMMARIZECOLUMNS by default anything else will have to be injected with TREATAS

SUMMARIZECOLUMNS doesn't see any filter context if it runs through the "Edit DAX" on an Excel Table connected to the Data Model.

 

Seems like there is no solution to this issue.

I wouldn't say that, as you haven't provided any DAX or data at all.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Kudoed Authors