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
PBJ
Regular Visitor

Cumulative Amounts

Hi everyone!

 

I am trying to calculate the cumulative sums of amounts in different months within a year. In excel, I would do so by locking the first value in the first month of interest and then calculate the following months/values by adding the previous figures to them.

For instance, the amounts in C4 is the result of =SUM($B$2:B4)

 

 yearcumulative year
July100000100000
August35975135975
September23423159398

 

How can I perform the same calculation in PowerBi-what would be the appropriate command?I have a much lengthier list and in excel I would use the SUMIFs formulat to aid the operation.

 

1 ACCEPTED SOLUTION
kcantor
Community Champion
Community Champion

@PBJ

You can do something like this YTD calculation. If you need it to cover different custom calendars, jsut add a custom calendar.

https://blog.crossjoin.co.uk/2009/12/01/first-steps-in-dax-year-to-date/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
v-haibl-msft
Employee
Employee

@PBJ

 

If your data table is similar to below one. You should get the expected result with following measure provide by KGrice.

If you still cannot get it to work, could you please provide some sample data to us so that we can give an exact formula?

Cumulative Amounts_1.jpg

Running Total = 
CALCULATE (
    SUM ( Table2[Value] ),
    FILTER ( ALL ( Table2 ), Table2[Date] <= MAX ( Table2[Date] ) )
)

Cumulative Amounts_2.jpg

 

Best Regards,

Herbert

 

Super thanks for all of your comments, appreciate it. I eventually managed to work it out with TOTALYTD. But I also had to fix the date measure, as it was highlighted in your answers. Without a proper date, in fact, I was not able to pick up the right data - this is so as eventually my data set ended up having multiple years.

 

Thank you all for your input 🙂

 

 

v-haibl-msft
Employee
Employee

@PBJ

 

The measure provided by KGrice should be OK. You can also try to create a MonthNum column and a cumulative year column.

MonthNum = 
MONTH ( LEFT ( Table1[month], 3 ) & "/1" )
cumulative year = 
SUMX (
    FILTER ( Table1, Table1[MonthNum] <= EARLIER ( Table1[MonthNum] ) ),
    Table1[year]
)

Cumulative Amounts_1.jpg

Best Regards,

Herbert

Many thanks for your input.

 

I tried out the formula on my data/table. The formula seems to indeed add values for the respective month, however does not add them to the previous ones. So, for July, it yields the sum of all values in July. For August, it yields all values in August, but does not include July ones.

kcantor
Community Champion
Community Champion

@PBJ

You can do something like this YTD calculation. If you need it to cover different custom calendars, jsut add a custom calendar.

https://blog.crossjoin.co.uk/2009/12/01/first-steps-in-dax-year-to-date/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




KGrice
Memorable Member
Memorable Member

To do cumulative sums, you'll need a column that can be recognized as a number, such as Month Number. In this case, I used StartOfMonth, so my table looked like this:

 

StartOfMonth.PNG

That column will allow you to write a measure where you get the sum of all of your Year column where the StartOfMonth is less than or equal to your current row's StartOfMonth. You can then create a new measure:

 

CumulativeYearAmount = CALCULATE(SUM(TableName[YearAmount]), FILTER(ALL(TableName[StartOfMonth]), TableName[StartOfMonth] <= MAX(TableName[StartOfMonth])))

 

 Drag StartOfMonth, Year, and CumulativeYearAmount onto a table in PowerBI and you should see this:

 

CumulativeTotalTable.PNG

 

 

You could finally format the StartOfMonth column if you want it to look more like just the month name. The MMMM, yyyy option is the closest I could find.

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.