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
sprakash1192
Helper II
Helper II

Running total negative and slow

I am trying to calculate net inventory om hand on selected dates by doing running total on inventory transactions of all the stock receipts and stock issues. The net total is fine, but I start drilling down to some quarters / dates, the running total is negative, which should not be. I am using a calendar table. Here is my DAX query:

 
Total EA OH running total in Date =
CALCULATE(
    SUM('Inv Txns by Date'[Total EA OH]),
    FILTER(
        ALLSELECTED('Calendar'[Date]),
        ISONORAFTER('Calendar'[Date], MAX('Calendar'[Date]), DESC)
    )
 
 
Also, the performance of this query is slow. I have a lot of inventory transactions, can that be a cause? Or do I need to apply some indexes? The query takes 35 seconds to refresh everytime I change a filter or do drill up / down.
 
Please help me to enhance mmy query.
)

 

1 ACCEPTED SOLUTION

Hi @sprakash1192 ,

 

We need to calculate the value of the same period first, then accumulate. So we can create two measures to meet your requirement.

 

Measrue2 = 
CALCULATE(
SUM('Table'[values]),
SAMEPERIODLASTYEAR('Table'[Date]),ALLSELECTED('Table'))
same period last year = 
CALCULATE([Measrue2],FILTER(ALLSELECTED('Table'),'Table'[Date]<=MAX('Table'[Date])))

 

The result like this,

 

Running 1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@sprakash1192  , try like

CALCULATE(
SUM('Inv Txns by Date'[Total EA OH]),
FILTER(
ALLSELECTED('Calendar'[Date]),
'Calendar'[Date]<= MAX('Calendar'[Date])
)

Thank you Amit. That helps. My DAX query is still slow. I think it is because of the sheer amount of data.

 

Also, how do I calculate the running total for the same period last year and do a comparison?

Hi @sprakash1192 ,

 

We need to calculate the value of the same period first, then accumulate. So we can create two measures to meet your requirement.

 

Measrue2 = 
CALCULATE(
SUM('Table'[values]),
SAMEPERIODLASTYEAR('Table'[Date]),ALLSELECTED('Table'))
same period last year = 
CALCULATE([Measrue2],FILTER(ALLSELECTED('Table'),'Table'[Date]<=MAX('Table'[Date])))

 

The result like this,

 

Running 1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

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.