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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Analitika
Post Prodigy
Post Prodigy

DAX to Calculate Opening and Closing Stock, Exceed memory limit

 

 

I have a large data table in Data Model from 2000 year

Why simple measure exceed memory limits? And how to get rid of that?

 

Opening Stock=
CALCULATE (
SUM ( Table1[value] ),
FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] < MIN ( 'Date'[Date] ) )
)

 

 

Closing Stock=
CALCULATE (
SUM ( Table1[value] ),
FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) )
)

 

Analitika_0-1609234285042.png

Loading only if one month selected

 

 

 
 
 
 
 

 

7 REPLIES 7
v-alq-msft
Community Support
Community Support

Hi, @Analitika 

 

I'd like to suggest you refer to the following guidence to improve Power BI performance by optimizing DAX.

Improve Power BI Performance by Optimizing DAX 

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@Analitika Couple thoughts on this. First, incredibly difficult to troubleshoot performance related DAX without the model so all I can do is kind of guess. I wrote a two part series on DAX performance optimization that might help. 

Unsure if it will help, but perhaps try using a separate date table for your slicer that is not related to your main date table. You would then be able to ditch your ALL statement. Also, if you Date table is related to your fact table, you could also try filtering the table directly versus going through the Date table once you have a separate disconnected date table for your slicer. My concern with the ALL statement is that it looks like you are bringing the entirety of your fact table into context and I can't imagine that is optimal. Also, I would definitely turn off Auto date/time and the reason is that this blows up the size of your date table to huge proportions, usually unnecessarily. Then, using ALL to bring in your entire date table you have to load this behemonth into memory. Getting rid of Auto date/time should drastically reduce the size of your date table in your data model and then it may fit into memory.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@Analitika - Would have to understand the data model better to understand what is going on. Do you really need the ALL in there? With the ALL in there you are overriding context forcing the measure to load the entire date table into memory and then pare it back down versus just taking what it has in context and filtering it. How big is your Date table? Have you turned off Auto date/time?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

I have aa slicer 

Analitika_0-1609252983141.png

 

it filled with auto date/time  'Date'[Date]  but sliced to last 3 years to reduce slicer dates (just need show dates for last 3 years)

 

but MIN(Table1[date]) is 2000.01.01

 

So for Opening Stock i need to sum all in Table1[value] from 2000.01.01 until MIN(Date[Date]) selected by slicer

So for Closing Stock i need to sum all in Table1[value] from 2000.01.01 until MAX(Date[Date]) selected by slicer

 

amitchandak
Super User
Super User

@parry2k , @Greg_Deckler , what is best way to this in performance efficient way?

amitchandak
Super User
Super User

inefficient DAX calculations can cause a query to try to grab a lot of memory

 

so how to write efficient calculation for that purpose?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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