Forum Discussion
Simple recursive calculation - Power Query
- 6 years ago
Greg_DecklerHello Greg
Thank you for your reply and for sharing those articles, it help me a lot!
Still struggle a little to refer the values I wanted to use in calculations, but I manage to solve this problem creating a new column of lists instead (if you know a better way to do it, I would love to hear it).
Here is the code I used, in case someone else want to know:let fxBalance = (InitialValue,Payments,InterestRate,Counter,Index) => let Correction = if InterestRate{Counter-1} = null then 0 else InitialValue*InterestRate{Counter-1}, FinalBalance = if InitialValue - Payments{Counter-1} + Correction < 0 then 0 else InitialValue - Payments{Counter-1} + Correction, Return = if FinalBalance < 0 or Counter >= Index then FinalBalance else @fxBalance(FinalBalance,Payments,InterestRate,Counter+1,Index) in Return in fxBalance
Using the function:Table.AddColumn(#"Personalização Adicionada6", "Personalizar.1", each fxBalance([Initial Value],[Payments List],[Interest Rate List],1,[Index]))
The results:
ty
brunoiadocicco Last time I was messing around with recursion in Power Query, it had to do with fractals. Attaching PBIX below. Here is a link to the articles. The articles have links to download additional PBIX file examples. Should be something in there to help your particular situation, I think I did a different solution for recursion in each article.
- brunoiadocicco6 years agoFrequent Visitor
Greg_DecklerHello Greg
Thank you for your reply and for sharing those articles, it help me a lot!
Still struggle a little to refer the values I wanted to use in calculations, but I manage to solve this problem creating a new column of lists instead (if you know a better way to do it, I would love to hear it).
Here is the code I used, in case someone else want to know:let fxBalance = (InitialValue,Payments,InterestRate,Counter,Index) => let Correction = if InterestRate{Counter-1} = null then 0 else InitialValue*InterestRate{Counter-1}, FinalBalance = if InitialValue - Payments{Counter-1} + Correction < 0 then 0 else InitialValue - Payments{Counter-1} + Correction, Return = if FinalBalance < 0 or Counter >= Index then FinalBalance else @fxBalance(FinalBalance,Payments,InterestRate,Counter+1,Index) in Return in fxBalance
Using the function:Table.AddColumn(#"Personalização Adicionada6", "Personalizar.1", each fxBalance([Initial Value],[Payments List],[Interest Rate List],1,[Index]))
The results:
ty