Forum Discussion
Interest Calculation
Dear Experts,
I need your help and ideas, I have the below data and wante to allocate the monthly interst to each mont, Is ther any ideas?
Thanks
| Loan Number | Amount | Rate | From | to | Days | Interest |
| Loan 1 | $ 5,000.00 | 2.00% | 15-Jan | 15-Feb | 31.00 | $ 8.61 |
| Loan 1 | $ 5,000.00 | 2.25% | 15-Feb | 15-Mar | 28.00 | $ 8.75 |
| Loan 1 | $ 5,000.00 | 2.50% | 15-Mar | 15-Apr | 31.00 | $ 10.76 |
| Loan 1 | $ 5,000.00 | 2.50% | 15-Apr | 2-May | 17.00 | $ 5.90 |
| Loan 5 | $ 10,000.00 | 2.60% | 15-Jan | 15-May | 120.00 | $ 86.67 |
| $ 120.69 | ||||||
| Month | Interest | |||||
| Jan | ? | |||||
| Feb | ? | |||||
| March | ? | |||||
| April | ? | |||||
| May | ? | |||||
| $ 120.69 |
Hi anwargabr ,
Actually I changed my mind. It seems "at least to me" that it is easier to unpivot the data using dax. I explained earlier how to create a simple date table in DAX. Now all you need to do is to create a new table by CROSSJOIN both Date and Loans tables to generate all combinations then filter down only to the relivant ones as per below code.FullData = VAR FullDateData = CROSSJOIN ( 'Date', Loans ) VAR ExistingDateData = FILTER ( FullDateData, [Date] > [From] && [Date] <= [to] ) RETURN ExistingDateDataThis is how the original data looks like
an this the how the unpivoted data looks like
Next you create the relationship between Date and FullData tables.
Last you need to create your measureInterest Amount = SUMX ( FullData, DIVIDE ( FullData[Amount] * FullData[Rate], 360, 0) )The results 100% matchews the calculations in your excel sheet.
Here is the link to download the Pbi file https://www.dropbox.com/t/axD7brB2Czc8br8V
Hi anwargabr
Sorry for the very late reply.Please refer to attached file for two options:
- Adjusting the calculated table as follows
- Creating a measure directly without creating a calculated table.
Option
14 Replies
- amitchandakSuper User
- anwargabrHelper I
amitchandak Thanks a lot my dear, will tyr to understand the file you've shared and apply it on my own file.
- tamerj1Community Champion
Hi anwargabr ,
First you need to create a table that contains all the dates included in order to calculate the interest per each date. Let's call it "PerDate" table. You can use the following simple code:PerDate = CALENDAR ( Min ( Loans[From] ), Max ( Loans[to] ) ) ​In this table create a new month calculated cloumn:
Month = FORMAT ( DATE ( 1, MONTH ( PerDate[Date] ), 1 ) , "mmm" )Then add another calculated column to calculate the average daily interest as follows:
Interest = VAR CurrentDate = 'PerDate'[Date] VAR CrrentLoans = FILTER ( Loans, Loans[From] <= CurrentDate && Loans[to] > CurrentDate ) VAR Result = CALCULATE ( SUMX ( CrrentLoans, DIVIDE ( Loans[Interest], Loans[Days] ) ) ) RETURN ResultBasically, this code filters the loans table to include only the rows that include each date. Then it iterates over the filtered table to calculate the average interst per each day.
Now you can simply create your measure:Ineterst ($) = SUM ( PerDate[Interest] )Then create your report agregated by Month:
- tamerj1Community Champion
Most welcome. Please let me know if you need the Pbi file.
- anwargabrHelper I
Thanks Dear, I have followed your explanition and creat the Pbi, now if I want to change the interst DAX to reflect the below formula
[@Amount]*[@Rate]/360*[@Days]
Is it applicable as a new column or new measure?
also haow can we filter the result by laon number?
, the result should be exactly same below
- v-xiaotangCommunity Support
Hi anwargabr
Have you solved this question with tamerj1's help? If you have solved the question, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.
If you need more help, please let me know.
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
- anwargabrHelper I
Gents
The above answer of Mr. tamerj1 is great and helped me to satrt the dashboard. Howerver, another duplication issue came, let me explained:first, I was preparing this sheet on monthly basis and add new column called "Reporting Month", then at end of each month I copy the data and past it for the new month and do the movemnent "add new loans or make settled loans Zero" so i can track and see the monthly movement of the outstanding loans during the year, it's ok to see the outstanding but when it comes to Interest Calculation, there are some loans booked for more than 30 days duplicated in the new DATE column created by CROSSJOIN table
so if loan ref 1 is from 1 Jan to 30 March, if I just use filter of Reporting Month "Jan", the loan will created 90 rows which is right but when I add Feb and March, it creted another 90 and so on.
If I created a unique number for the loan REF, Is there any DAX could be added to the table to remove any duplication in the created DATE column based on the unique REF, so for each loan REF no duplication DATE.
Thanks