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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
biswad
Advocate I
Advocate I

Cumulative total across measure value

Hi everyone, 

 

I have few measures which calculate Total number of case created , case closed , net change per month. 

 

I would like to create another measure called "Stock" which will add the value of "Net Change" into next month. For example we start with stock value as 7 which is the "Net Change" value for the month of January , as we move to February I would like the measure to calculate stock value of February as sum of January Stock value  + Net Change of February  = 7+2= 9.

 

Similary I would like to calculate the Stock of March as sum of February Stock Value +March Net Change =9+2=12.

 

Any help on how to calculate the stock column would be greatly appriciated.

 

MonthTotal CreatedTotal CloseNet ChangeStock
January14777
February5329
March1210212
April64214
May210-86
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

There's a mistake in your sample data. March should be 9+2 = 11, not 12.

What you actually need to calculate here is the running total of net change for all months up to and including the current month. You can do that with

Stock =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR DatesToUse =
    CALCULATETABLE ( VALUES ( 'Date'[Year month] ), 'Date'[Date] <= ReferenceDate )
VAR Result =
    SUMX ( DatesToUse, [Net change] )
RETURN
    Result

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

There's a mistake in your sample data. March should be 9+2 = 11, not 12.

What you actually need to calculate here is the running total of net change for all months up to and including the current month. You can do that with

Stock =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR DatesToUse =
    CALCULATETABLE ( VALUES ( 'Date'[Year month] ), 'Date'[Date] <= ReferenceDate )
VAR Result =
    SUMX ( DatesToUse, [Net change] )
RETURN
    Result

Thank you so much, it took me  a while to understand the logic. much appriciated your help. 

bhanu_gautam
Super User
Super User

@biswad , Create a new measure for Stock:

DAX
Stock =
VAR CurrentMonth = MAX('Table'[Month])
RETURN
CALCULATE(
SUM('Table'[Net Change]),
FILTER(
ALL('Table'),
'Table'[Month] <= CurrentMonth
)
)

 

Make sure that your data is sorted by the "Month" column in the correct order. You can do this by creating a sort column if necessary.

 

Add the "Stock" measure to your table visual in Power BI. This will display the cumulative total of the "Net Change" for each month, effectively giving you the "Stock" value as described.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






thank you for your response brother, but my data is taking the month from a created on column which is already in the table. The below query solves the issue. much appriciated. 

Stock =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR DatesToUse =
    CALCULATETABLE ( VALUES ( 'Date'[Year month] ), 'Date'[Date] <= ReferenceDate )
VAR Result =
    SUMX ( DatesToUse, [Net change] )
RETURN
    Result

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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