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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
rwychan9
Regular Visitor

How do I avoid circular dependency when 2 columns require the earlier results of each other

Hi all,

I have a circular dependency that I am unable to solve after a week of trying.

 

There are 2 tables in the attachment:

  • TESTbondTransactions lists out transactions detail.
    • Settlement date is the transactions date
    • Book Value is Quantity x Price /100
    • Start/End Range is the range that this transaction is active, i.e. the 'Start Range' is the transactions date of the first purchase, and 'End Range' is the date that it was fully sold off, or the maturity date of the bond. In this case, I filtered the results to only have 1 bond to work with and it has not been completely sold, so end date is the maturity of May 3, 2027.
    • QuantitySold - this will be between 0 and -100%; this denotes what percentage of the position (at the time of sale) was sold.
    • PrevMonthCarryingValue - this looks into the bondSchedule table and find the [Carrying Value] as of the previous month-end.
  • TESTbondSchedule is the amortization schedule.
    • MonthlyDates shows the end-of-month from the Start Range to the End Range.
    • Start/End Range comes from the Transactions table.
    • Amortized (SL) is the straight-line amortization taken each month.
    • Book Value comes from the Transactions table, but will change through time based on transactions.

The issue that I have is the Carrying Value. In the bondSchedule, the [Carrying Value] of a bond starts off as the [Book Value] at purchase, then as the month goes on, the monthly [Amortized (SL)] gets added.

 

When there is a partial sale (i.e. from the bondTransactions table, the sale of 76.78% of position on July 10th, 2023, the gain/loss will be calculated by: [PrevMonthCarryingValue] * [QuantitySold] - [Book Value]. To explain, the gain/loss is comparing the [Carrying Value] against the [Book Value] of the transaction (based on % of position sold).

 

My issue is once there's a gain/loss, it needs to be carried in the [Carrying Value] going forward. i.e. in the "07-31-2023" row on the bondSchedule, the Carrying Value should be $123268.24 + (-67748.11).

 

I am getting a circular dependency for obvious reason but I am not sure how to solve this problem. bondSchedule Carrying Value = Book Value + Cumulative Amortization + Gains/Losses, but then to calculate a gain/loss in the bondTransactions table, I need to bring Carrying Value in.

 

I tried calculating the Carrying Value directly in the gain/loss formula in the bondTransactions table, but then I'll also have to sum all the gain/loss up to that point if there are more than one partial sale, and I couldn't get it to work. I am fairly new to Power Bi so any help would be appreciated.

 

The example is a simple 1 security, 1 client, 1 partial sale transaction, but the full dataset inclues multiple clients and multiple partial sales. 

 

Thanks!

 

Sample Bond Schedule 

2 REPLIES 2
amitchandak
Super User
Super User

@rwychan9 , You have to build this using cumulative only. As power bi dax does not support recursive

 

example like we do Intital Inventory + In -Out

Inventory / OnHand
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

 

Power BI Inventory On Hand
Power BI Inventory On Hand: https://youtu.be/nKbJ9Cpb-Aw

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

Thank you for your suggestion. I will give it a shot.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.