// Add Stundung to last Tilgung
// col_Stundung gets its items from the Dataverse table(Tilgungsplans)
// Just a few variables i need later
If(Dropdown1.SelectedText.Value = "am Tilgungsende",
Set(var_LastItem, Last(col_Stundung));
Set(var_CurrentTilgung, Gallery2.Selected);
Set(new_Tilgungsanteil, var_LastItem.Tilgungsanteil + var_CurrentTilgung.Tilgungsanteil);
Set(new_OffenerKredit, var_LastItem.'Offener Kreditbetrag' + var_CurrentTilgung.'fällige Rückzahlung');
Set(new_Zinsen, var_LastItem.Zinsen + var_CurrentTilgung.Zinsen);
Set(new_fälligeRückzahlung, var_LastItem.'fällige Rückzahlung' + var_CurrentTilgung.'fällige Rückzahlung');
Set(new_Sondertilgung, var_LastItem.'Sondertilgung zum Periodenende' + var_CurrentTilgung.'Sondertilgung zum Periodenende');
// Empty Collection
Clear(col_StundungDone);
// Filter col_Stundung to only include items after the selected one. This is working
ClearCollect(col_Stundung, Filter(col_Stundung, Value('Rate(per Fälligkeit)') >= Value(var_CurrentTilgung.'Rate(per Fälligkeit)')));
// THIS IS THE PART WHERE I NEED HELP
// I want that it iterates through all the elements in col_Stundung and update the four columns with the data of the next item in the list. I use a Dataverse table (Tilgungsplans) for the Lookups so that it does not matter which element is updated first.
ForAll(col_Stundung,
Collect(col_StundungDone,
{
'Tilgungsplan': ThisRecord.Tilgungsplan,
'Offener Kreditbetrag': Text(LookUp(Tilgungsplans, Kundenkredit= var_CurrentTilgung.Kundenkredit && Value('Rate(per Fälligkeit)') = (Value(col_Stundung[@'Rate(per Fälligkeit)'])-1)).'Offener Kreditbetrag'),
'Tilgungsanteil': Text(LookUp(Tilgungsplans, Kundenkredit= var_CurrentTilgung.Kundenkredit && Value('Rate(per Fälligkeit)') = (Value(col_Stundung[@'Rate(per Fälligkeit)'])-1)).Tilgungsanteil),
'Sondertilgung zum Periodenende': Text(LookUp(Tilgungsplans, Kundenkredit= var_CurrentTilgung.Kundenkredit && Value('Rate(per Fälligkeit)') = (Value(col_Stundung[@'Rate(per Fälligkeit)'])-1)).'Sondertilgung zum Periodenende'),
'Zinsen': Text(LookUp(Tilgungsplans, Kundenkredit= var_CurrentTilgung.Kundenkredit && Value('Rate(per Fälligkeit)') = (Value(col_Stundung[@'Rate(per Fälligkeit)'])-1)).Zinsen),
'fällige Rückzahlung': Text(LookUp(Tilgungsplans, Kundenkredit= var_CurrentTilgung.Kundenkredit && Value('Rate(per Fälligkeit)') = (Value(col_Stundung[@'Rate(per Fälligkeit)'])-1)).'fällige Rückzahlung')
}
));
// But the code above just returns Blanks most of the time, except Tilgungsplan, that column is always filled
// Patch all the updated rows in the table
ForAll(col_StundungDone,
Patch(Tilgungsplans,
LookUp(Tilgungsplans, Tilgungsplan = col_StundungDone[@Tilgungsplan]),
{
'Offener Kreditbetrag': ThisRecord.'Offener Kreditbetrag',
Tilgungsanteil: ThisRecord.Tilgungsanteil,
'Sondertilgung zum Periodenende': ThisRecord.'Sondertilgung zum Periodenende',
Zinsen: ThisRecord.Zinsen,
'fällige Rückzahlung': ThisRecord.'fällige Rückzahlung'
}
));
// Update the last item in the Tilgungsplan with the due payments from the selected item
Patch(Tilgungsplans,
LookUp(Tilgungsplans, Tilgungsplan = var_LastItem.Tilgungsplan),
{
Tilgungsanteil: new_Tilgungsanteil,
'Offener Kreditbetrag': new_OffenerKredit,
Zinsen: new_Zinsen,
'fällige Rückzahlung': new_fälligeRückzahlung,
'Sondertilgung zum Periodenende': new_Sondertilgung
});
// Update selected to no pay
Patch(Tilgungsplans,
LookUp(Tilgungsplans, Tilgungsplan = var_CurrentTilgung.Tilgungsplan),
{
Tilgungsanteil: 0,
'fällige Rückzahlung': 0,
'Sondertilgung zum Periodenende': 0,
Zinsen: 0
});
);
// END OF CODE
The current code is either doing nothing or replacing all the data with blanks.
My table has a few more columns, so i thought it would easiest to do it that way
So if I have items
Rate / Offener Kreditbetrag / Tilgungsanteil / Zinsen / fällige Rückzahlung (Tilgungsanteil + Zinsen)
1 / 15000 / 1000 / 0 / 1000
2 / 14000 / 1000 / 0 / 1000
3 / 13000 / 1000 / 0 / 1000
4 / 12000 / 1000 / 0 / 1000
5 / 11000 / 1000 / 0 / 1000
...
14 / 2000 / 1000 / 0 / 1000
15 / 1000 / 1000 / 0 / 1000
and I select the item with 12000
the new entries should look like this
Instalment(Rate) / Outstanding Amount / repayment amount / Interest / due payment (repayment amount + Interest)
1 / 15000 / 1000 / 0 / 1000
2 / 14000 / 1000 / 0 / 1000
3 / 13000 / 1000 / 0 / 1000
4 / 12000 / 0 / 0 / 0 // I don't get paid here
5 / 12000 / 1000 / 0 / 1000
6 / 11000 / 1000 / 0 / 1000
...
14 / 3000 / 1000 / 0 / 1000
15 / 2000 / 2000 / 0 / 2000 // I get the due payment here
Any help will be appreciated.
I am also open for new/better solutions to the whole problem.
Thanks in advance!