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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
hmayol
New Member

Accumulate Surplus and Deficit

Hello, 

I have a table with transactions, each transaction has a "gap". The gap indicates either a surplus (positive gap) or a deficit (negative gap). I am trying to calculate the accumulated deficit.

  • The accumulated deficit depends on whether there is an accumulated surplus on the previous line to cover the current deficit or not. 
    • Current surplus (gap) cannot be applied to previous deficit (accumulated)
    • Current deficit (gap) can only be offset by previous surplus (accumulated)

 

Here is how I was able to achieve it in Excel: 

the formula for accumulated surplus =IF(C3+E2>0, 0, C3+E2)

the formula for accumulated deficit `=IF(C3<=0,D2,IF(AND(C3>0,C3+E2<0),D2,(C3+E2+D2)))

nGapAccumulated DeficitAccumulated Surplus
1000
220200
3-1220-12
4520-7
511240
60240
7-324-3
8124-2
9-724-9
10-224-11
11-124-12
12324-9
13024-9

 

Any help would be appreciated! 

3 REPLIES 3
Anonymous
Not applicable

Hello! 

Did you figure out a way to do this? 🙂

Anonymous
Not applicable

@hmayol ,

 

Could you provide some sample data and the expected result, so that I can help you.

 

The information that you have provided is not clear. What is C3, E2 and D2. I think this are the cell references in the excel file.

 

Please provide sample data to understand your requirement.

 

Regards,

Pavan Vanguri.

@Anonymous 

 

I have two files here 

  1. the pbix file has two columns
    1. customer_id-patient_id-GPI10-dispense_index: this column serves as a dispense index. Each customer_id-patient_id-GPI10 values has n dispenses. The accumulated deficit needs to be calculated per customer_id-patient_id-GPI10 
    2. Refill_Gap_PDC: this is the column that identifies a surplus or deficit per dispense.
  2. The xlsx file is a sample calculation of what the final outcome should be in power bi with one customer_id-patient_id-GPI10 example. 

Let me know if you need anymore information. 

 

Thanks, 

 

Hector M.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.