web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Updating Collection wi...
Power Apps
Answered

Updating Collection with data from next item

(0) ShareShare
ReportReport
Posted on by
Hi everyone, 

I have a problem in PowerApps and I just cannot find a solution for it. 

The app should help me calculating and updating a repayment plan. 
The calculating part works alright, but I want a feature where the User can say that he/she is not able to pay that month and that he/she pays it at the end, with the last repayment of the plan. 

I thought it would be best if Power apps just iterates through all of the items in the collection col_Stundung, in which all the repayments of the plan are listed,
and updates the current item with the data from the next item. I get the next item via the Rate(per Fälligkeit)+1

Now to my code: 
First I am sorry that part of it is in german. 
The parts in yellow are  for further explaination 
// 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!
I have the same question (0)
  • Verified answer
    AmínAA Profile Picture
    1,228 Moderator on at
    Greetings

    Maybe I’m failing to understand how you App is supposed to work, but I get the feeling that the either the data architecture or the App functionality is overcomplicated for what should be a simple matter. . . I would recommend you change how it’s supposed to work, because I’m failing to see the benefits of having all the payment plan pre-calculated in advance like this and stored in a table.

    With that being said, I’m not about to just drop this and leave hahaha! With some help of a colleague we’ve come up with a code that might or might not help fix your current code, since we don’t have that much time to recreate what you have in order to test it out . . . Here’s what we’ve got (Sorry in advance if we butchered any comment as we’ve used google translate to try and understand everything that was in german):
    // Set up variables for the selected item and last item
    If(
        Dropdown1.SelectedText.Value = "am Tilgungsende",
        Set(var_LastItem, Last(col_Stundung));  // Get the last item in the collection
        Set(var_CurrentTilgung, Gallery2.Selected);  // Get the currently selected item
        Set(new_Tilgungsanteil, var_LastItem.Tilgungsanteil + var_CurrentTilgung.Tilgungsanteil);  // Add repayment amount to last item
        Set(new_OffenerKredit, var_LastItem.'Offener Kreditbetrag' + var_CurrentTilgung.'fällige Rückzahlung');  // Add outstanding amount to last item
        Set(new_Zinsen, var_LastItem.Zinsen + var_CurrentTilgung.Zinsen);  // Add interest to last item
        Set(new_fälligeRückzahlung, var_LastItem.'fällige Rückzahlung' + var_CurrentTilgung.'fällige Rückzahlung');  // Add due payment to last item
        Set(new_Sondertilgung, var_LastItem.'Sondertilgung zum Periodenende' + var_CurrentTilgung.'Sondertilgung zum Periodenende');  // Add special repayment to last item
    
        // Add data from the "next item" to the collection
        ClearCollect(
            col_StundungWithNext,
            AddColumns(
                col_Stundung,
                "NextOffenerKreditbetrag",
                LookUp(
                    col_Stundung,
                    Value('Rate(per Fälligkeit)') = Value(ThisRecord.'Rate(per Fälligkeit)') + 1
                ).'Offener Kreditbetrag',
                "NextTilgungsanteil",
                LookUp(
                    col_Stundung,
                    Value('Rate(per Fälligkeit)') = Value(ThisRecord.'Rate(per Fälligkeit)') + 1
                ).Tilgungsanteil,
                "NextZinsen",
                LookUp(
                    col_Stundung,
                    Value('Rate(per Fälligkeit)') = Value(ThisRecord.'Rate(per Fälligkeit)') + 1
                ).Zinsen,
                "NextFälligeRückzahlung",
                LookUp(
                    col_Stundung,
                    Value('Rate(per Fälligkeit)') = Value(ThisRecord.'Rate(per Fälligkeit)') + 1
                ).'fällige Rückzahlung',
                "NextSondertilgung",
                LookUp(
                    col_Stundung,
                    Value('Rate(per Fälligkeit)') = Value(ThisRecord.'Rate(per Fälligkeit)') + 1
                ).'Sondertilgung zum Periodenende'
            )
        );
    
        // Update repayment plan items with the "next item" data
        ForAll(
            col_StundungWithNext,
            Patch(
                Tilgungsplans,
                LookUp(Tilgungsplans, Tilgungsplan = ThisRecord.Tilgungsplan),  // Find the current record to update
                {
                    'Offener Kreditbetrag': ThisRecord.NextOffenerKreditbetrag,
                    Tilgungsanteil: ThisRecord.NextTilgungsanteil,
                    Zinsen: ThisRecord.NextZinsen,
                    'fällige Rückzahlung': ThisRecord.NextFälligeRückzahlung,
                    'Sondertilgung zum Periodenende': ThisRecord.NextSondertilgung
                }
            )
        );
    
        // Update the last item in the repayment plan
        Patch(
            Tilgungsplans,
            LookUp(Tilgungsplans, Tilgungsplan = var_LastItem.Tilgungsplan),  // Find the last item
            {
                Tilgungsanteil: new_Tilgungsanteil,
                'Offener Kreditbetrag': new_OffenerKredit,
                Zinsen: new_Zinsen,
                'fällige Rückzahlung': new_fälligeRückzahlung,
                'Sondertilgung zum Periodenende': new_Sondertilgung
            }
        );
    
        // Set the selected item to no payment for this period
        Patch(
            Tilgungsplans,
            LookUp(Tilgungsplans, Tilgungsplan = var_CurrentTilgung.Tilgungsplan),  // Find the selected item
            {
                Tilgungsanteil: 0,
                'fällige Rückzahlung': 0,
                'Sondertilgung zum Periodenende': 0,
                Zinsen: 0
            }
        )
    );
     

    If you like my response, please give it a Thumbs Up. Should this reply solve your question, please mark your post as Solved. Otherwise, feel free to reply to my answer for further help.
    Connect with me if you feel like it!
  • AmínAA Profile Picture
    1,228 Moderator on at
    Greetings @CU07011509-1
     
    It has been a few months since I've tried to help you out on this. Did this get solved in the end?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 93 Most Valuable Professional

#2
Haque Profile Picture

Haque 81

#3
Valantis Profile Picture

Valantis 49

Last 30 days Overall leaderboard