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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
mhrkhader01
Helper I
Helper I

how to write a Measure or a calculated column to calculate Accumulative previous Month row total

Dear Team,

 

Greetings

 

i have the follwing columns

NoDateSalesTargetDiffAccumulative
11-Jan-21>>103904>>108371>>-4467>>0>>
21-Feb-21>>184515>>101049>>83466>>83466>>
31-Mar-21>>175449>>200000>>-24551>>58915>>
41-Apr-21>>193121>>300000>>-106879>>0>>
51-May-21>>182197>>200000>>-17803>>0>>
61-Jun-21>>170824>>100000>>70824>>70824>>
71-Jul-21>>164027>>200000>>-35973>>34851>>
81-Aug-21>>167026>>200000>>-32974>>1877>>
91-Sep-21>>111350>>200000>>-88650>>0>>
101-Oct-21>>188179>>100000>>88179>>88179>>
111-Nov-21>>161467>>100000>>61467>>149646>>
121-Dec-21>>147271>>250000>>-102729>>46917>>
131-Jan-22>>106566>>250000>>-143434>>0>>
141-Feb-22>>182679>>250000>>-67321>>0>>
151-Mar-22>>164760>>250000>>-85240>>0>>


accumulative = accumulative in previous row+ saving in the current row

the scenario is that when i achived more that the target, i need to save the increase more than the target in accumulative column

so may be next month i will achive less that the Target,  i need accumulative column to be deducted for the shortage for current row month, when the value of diff is in minues and there is no more saving it should give (0).like in row number 10

 we have increase in sales more than target, so we need to save that amount in Accumulative column, which is (88179) , but for row 11, since we have increase also, i need to add row number 11increase to the previous row accumulative, how to do that. 

 

regards

Maher

 

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

@mhrkhader01 , can't sent files, but the steps are very simple in PQ.

For Difference column:

1. Click Add Column - Custom Column

2. 

ERD_0-1620711937185.png

For Accumulative column:

1. Click Add Column - Custom Column

2. 

ERD_1-1620711995373.png

You can copy/past the code from the previous message, just change the column names if different.

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

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

Stand with Ukraine!


Here is an official way you can support Ukraine financially:
Come Back Alive foundation: https://savelife.in.ua/en/

Thank you!

View solution in original post

5 REPLIES 5
ERD
Community Champion
Community Champion

Hi @mhrkhader01 ,

I don't know all the prerequisites and how your data looks like, but one of the ways is to use Power Query.

#"Added Custom" = Table.AddColumn(#"Previous step name", "Diff", each [Sales] - [Target]),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Accumulative", each List.Accumulate(
    List.Range(#"Added Custom"[Diff],0,[No]),0,(state,current)
    => if state+current < 0 then 0 else state+current
    ))
in
#"Added Custom2"

ERD_0-1620398045646.png

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

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

Stand with Ukraine!


Here is an official way you can support Ukraine financially:
Come Back Alive foundation: https://savelife.in.ua/en/

Thank you!

Dear ERD,

 

thank you so much. really appreciated.

but...can i have the same thing using DAX Measure in PowerPivot?

Regards

Maher

Dear ERD,

thanks, can i have the file?

ERD
Community Champion
Community Champion

@mhrkhader01 , can't sent files, but the steps are very simple in PQ.

For Difference column:

1. Click Add Column - Custom Column

2. 

ERD_0-1620711937185.png

For Accumulative column:

1. Click Add Column - Custom Column

2. 

ERD_1-1620711995373.png

You can copy/past the code from the previous message, just change the column names if different.

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

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

Stand with Ukraine!


Here is an official way you can support Ukraine financially:
Come Back Alive foundation: https://savelife.in.ua/en/

Thank you!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.