March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Data and XL solution and attempts to solve with Power Query
I have been trying to solve this problem with power query. I started by using refer to previous row methods but thought these would likely be "too expensive" when used on my production dataset (about 500k rows) judging by how slow they were even with the sample data. I have then tried to make it work with list.accumulate and/or list.generate but, without success. The sample data and my attempts with power query along with a standard (structured table) XL solution which does actually work , even with 500k rows, and shows the result I'm aiming at (screenshot below) are in the XL file linked to above. But, if I can do this in PQ that's where I'd rather have it done.
Hi @androo235 ,
this function calculates the compound interest:
( RTColumnName as text, MyTable as table, ValueColumn as text, InterestColumn as text) =>
let
Source = MyTable,
BuffValues = Table.Buffer( MyTable ),
RunningTotal =
List.Skip(
List.Generate (
() => [ RT = 0, ValueColumn), RowIndex = 0 ],
each [RowIndex] <= Table.RowCount(BuffValues),
each [ RT = ([RT] + Record.Field(BuffValues{[RowIndex]}, ValueColumn) ) * (1 + Record.Field(BuffValues{[RowIndex]}, InterestColumn)),
RowIndex = [RowIndex] + 1 ],
each [RT]
)
),
#"Combined Table + RT" =
Table.FromColumns(
Table.ToColumns( MyTable )
& { Value.ReplaceType( RunningTotal, type {Int64.Type} ) } ,
Table.ColumnNames( MyTable ) & { RTColumnName } )
in
#"Combined Table + RT"
also check the solution with "fnCompounding" in the file attached.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
thanks Imke. Here's the link again (a fresh one even if it looks and is the same) It's to my personal one-drive and says it's an "anyone can view" link and is set to open in a new page. I'm assuming "can view" includes being able to download and then edit it. If it isn't possible to download and edit please tell me and I'll just have to post a "can edit" link. Data and XL Solution and attempt to solve with Power Query Thanks.
Hi @androo235 ,
it should be possible to do this fast in PQ using the right method:
Memory efficient clustered running total in Power BI – (thebiccountant.com)
I have been using this on millions of rows without any issues.
I you are having trouble applying it to your case, please re-open the file you had shared.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Seems no-one has an answer to this.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
34 | |
30 | |
20 | |
19 | |
12 |