Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
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 |
Solved! Go to Solution.
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
ExistingDateData
This 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 measure
Interest 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:
Option
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
Hi @anwargabr
Sorry for the very late reply.
Please refer to attached file for two options:
Option
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.
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
Result
Basically, 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:
Most welcome. Please let me know if you need the Pbi file.
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
Good Moring @anwargabr
Check the file here https://www.dropbox.com/t/poTbyLxMZFOPDbpS
Not sure if I understand your equation or how you calculated the monthly interest in this table. However, if you need to slice by Loan number then you need to create a measure as calculated columns are no evaluated in the filter context rather in the row context of the iterated table.
To filter the matrix by loan number you can either use the slicer or just click on the chart column. Also you can slice the chart by month by clicking on the month name in the matrix. Power Bi provides interactive visuals that can filter each other.
If you have any question regarding the four measures and the two calculated columns in the file, please feel free to let me know. If you find my input hepful and fulfills your requirements, please kudo and mak as Accepted Solution.
Thanks and have agreat day
Dear @tamerj1
Thanks for my late reply due to the reason I've explained to you in the private message.
I've attached both excel and Pbi files here
https://www.dropbox.com/s/hcqqplt4b19sn3a/Test%20Ditribute%20days.rar?dl=0
the interest fromua and the manual calcaultion for days are all in the excel sheet.
Thanks and Best Regards.
Thank you @anwargabr
Now it is clear. It can be done with totally with DAX code but this is not the standard method. As long as you are making a transformation in your work you better follow a professional standard in your data. DAX in either power Bi or Power Pivot likes to deal with Columnar unpivoted data. That means less columns more rows. In your example that means you need to have the inrest rate and the loan ammount for each bank/loan type for each date date. That would generate a table of more than 1000 rows. This is a an extremely small number of rows compared to what DAX can handle (milions of rows at a time). You can use either excel or power pivot to do that. I can help you out on this but it could be a good excersie for you.
Next you need a proper Date table which I will help you with it. The rest is a peice of cake.
Try to unpivot your data and I will do something from side as well. Have a great day!
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
ExistingDateData
This 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 measure
Interest 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
@tamerj1 Thanks and much apperciate dear Tamer, I will try it and let you know.
@anwargabr , refer to my blog and file, where I have done similar stuff
@amitchandak Thanks a lot my dear, will tyr to understand the file you've shared and apply it on my own file.
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
33 | |
15 | |
14 | |
13 | |
9 |
User | Count |
---|---|
58 | |
23 | |
22 | |
19 | |
13 |