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

Calculating Opening / Closing Balance

Hi team,

 

I'm trying to use a formule like that:

         Closing Balance = ( Opening Balance   + field1 + field2 )

 

However the "Opening Balance" is the previous value of "Closing Balance", when I try to get the previous value for closing balance, it is showing a error: "a circular occurrence was detected"..

 

eduardomarchesi_0-1674492933041.png

Do you now how I can fix it?

 

Rgds

Eduardo

 

9 REPLIES 9
Anonymous
Not applicable

Hi, just wondering if you could figure out the way to calculate the opening balance and closing balance the way you wanted?
Please let me know.

Thanks.

amitchandak
Super User
Super User

@eduardomarchesi , If this is recursive calculation like excel, that is not possible.

 

If it can be cumulative 

 

Opening = CALCULATE(SUM(Sales[Amount]),filter(all('Date'),'Date'[date] <Min ('Date'[date])))

 

Closing =  CALCULATE(SUM(Sales[Amount]),filter(all('Date'),'Date'[date] <= Max('Date'[date])))

 

Or you can consider

openingbalancemonth, openingbalancequarter, openingbalanceyear: https://youtu.be/6lzYOXI5wfo
Power BI Allocating Targets- closingbalancemonth, closingbalancequarter, closingbalanceyear:https://youtu.be/yPQ9UV37LOU

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak,

 

Thank you very much for your help!!

 

I've tried your suggestions but with no success.

As you can see below, I have got the previous values of "Closing Balance" and associated with "Opening Balance", so, this Opening Balance I need incluide in the formule to "Closing Balance" as you can check in the screen from excel example below.

PowerBI result:

eduardomarchesi_0-1674501243821.png

Excel example:

eduardomarchesi_1-1674501430278.png

 

Is it possible I send you my example and my data to take look and understand better the sctructure?

** I could not see the option to attach files here!! 

Rgds

Eduardo

 

 

 

I know this is an old post but wnating to see if this was successfully handled in the code? I have exactly same requirement and dealing with circular dependency issues

Hi,

I have solved a similar question in the attached files.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks, some adjustments to my case but you saved me , I was about to give up lol

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Here is how I handled the this issue. 

Opening Balance = 
VAR MinDateInContext = MIN('Table'[Date])
VAR EndOfPrevMonth = EOMONTH(MinDateInContext, -1)
VAR BaseAmount = 
    CALCULATE(
        SUM('Table'[Milk Amount]) + SUM('Table'[Bread Amount]) + SUM('Table'[Butter Amount]) , 
        FILTER(
            ALL('Table'), 
            'Table'[Date] <= EndOfPrevMonth
        )
    )
RETURN
    IF(
        ISBLANK(BaseAmount),
        BLANK(),
        BaseAmount + 500
    )

 

Closing Balance = 
VAR MaxDateInContext = MAX('Table'[Date])
VAR EndOMonth = EOMONTH(MaxDateInContext, 0)
VAR BaseAmount = 
    CALCULATE(
        SUM('Table'[Milk Amount]) + SUM('Table'[Bread Amount]) + SUM('Table'[Butter Amount]), 
        FILTER(
            ALL('Table'), 
            'Table'[Date] <= EndOMonth
        )
    )
RETURN
    IF(
        ISBLANK(BaseAmount),
        BLANK(),
        BaseAmount + 500
    )

Thanks so much for the code example. I will try and see. Was thinking about cummulative sum until the period end from start. Also, realized could do all the calculations based on Ending Balance alone and just refer the Next month's Beginning Balance to be prev month's ending balance without any complications to the code - thus probably avoiding the circular dependency issue. 

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.