Forum Discussion
How to Handle Circular dependency for Amortization Schedule
- 6 years ago
lbendlin amitchandak Anonymous Thanks to you all for your responses.
I figured I had to go a completely different route to avoid the circular dependency by creating all independent measures.
Solution:
- I finetuned Other Dax created
Monthly Payment
Monthly Payment= VAR __PresendtValue = MAX( 'Table'[Amount Borrowed]) Var __Rate = MAX( 'Table'[Rate]) Var __AllPeriod = CALCULATE(MAX(TableCalendar[Period]), ALL(TableCalendar)) Return PMT(__Rate, __AllPeriod, -__PresendtValue,0)Monthly Interest
Monthly Interest= VAR __PresendtValue = MAX( 'Table'[Amount Borrowed]) Var __Rate = MAX( 'Table'[Rate]) Var __Period = MAX(TableCalendar[Period]) Var __AllPeriod = CALCULATE(MAX(TableCalendar[Period]), ALL(TableCalendar)) Return IPMT(__Rate,__Period,__AllPeriod,-__PresendtValue,0)
Monthly PrincipalMonthly Principal= VAR __PresendtValue = MAX( 'Table'[Amount Borrowed]) Var __Rate = MAX( 'Table'[Rate]) Var __Period = MAX(TableCalendar[Period]) Var __AllPeriod = CALCULATE(MAX(TableCalendar[Period]), ALL(TableCalendar)) Return PPMT(__Rate,__Period,__AllPeriod,-__PresendtValue,0)- I created a new Dax for the Begining and Ending Balance
Begining Balance
Begining Balance= VAR __PresendtValue = MAX( 'Table'[Amount Borrowed]) Var __Rate = MAX( 'Table'[Rate]) Var __Period = MAX(TableCalendar[Period]) Var __AllPeriod = CALCULATE(MAX(TableCalendar[Period]), ALL(TableCalendar)) Var __PMT = PMT(__Rate, __AllPeriod, -__PresendtValue,0) Return FV(__Rate,__Period-1,__PMT,-__PresendtValue,0)
Ending BalanceEnding Balance= VAR __PresendtValue = MAX( 'Table'[Amount Borrowed]) Var __Rate = MAX( 'Table'[Rate]) Var __Period = MAX(TableCalendar[Period]) Var __AllPeriod = CALCULATE(MAX(TableCalendar[Period]), ALL(TableCalendar)) Var __StartPeriod =CALCULATE(Min(TableCalendar[Period]), ALL(TableCalendar)) Var __CUMPRINC = -CUMPRINC(__Rate,__AllPeriod,__PresendtValue,__StartPeriod,__Period,0) RETURN __PresendtValue - __CUMPRINCOutcome Of above dax
Thanks.
Eli
First of all, thank you for the details you provide. Makes it much easier to follow.
I agree that the beginning balance depends on the previous period's ending balance. But please explain why the ending balance would depend on the beginning balance? You should not need that, rather just do a SUMX over the current period.
What's the purpose of your calendar table? It looks incomplete. You will want to have a table of contiguous dates that (just) covers your fact dates.
lbendlin Thank you for your response, and the questions you have asked are very sensible.
Why the ending balance depend on the beginning balance ?
The Ending Balance = Beginning balance – Principal
- The beginning balance for the period 1 is known (the amount borrowed).
- However, the beginning balance for the Period 2 onwards (is not Known), as it is the Ending Balance of the Previous Period.
I am not sure how you mean by "do a SUMX over the current period". Can you please do this and see if you get the expected result as shown below?
Expected Result
What's the purpose of your calendar table?
To be honest at this point, the calendar table is not as useful, I could have easily created a period column on fact table given the one to one relationship.
But then when you think of it, even with the way it is, if I start generating, Quarters, Month Name or Days for further analysis it will become useful as I would not want to have those on the fact table.
But at this point, I am aware that it is not doing much in this test data.
- amitchandak6 years ago
Super User
Euto , I have just seen it. Seem like other super users are already helping. Just see if these functions can help you. In case it does not resolve. I will look back
openingbalancemonth,openingbalancequarter, openingbalanceyear
closingbalancemonth ,closingbalancequarter, closingbalanceyear