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 Apps
Unanswered

Loop problems

(0) ShareShare
ReportReport
Posted on by 2

I have several courses and some people (theses both are Microsoft lists) each course has a limited number of participants. Those who wants to join the course are randomly chosen. gebKurs is a slot for each guy to book a course ist is from gebKurs1 to gebKurs6. If he gets a free slot in the course the course goes from gebKurs to zugKurs. When one does not get a free space the course goes from gebKurs to nowhere. I did it for the first course this way:

 

Set(schleifenindex;CountRows(Kurse));;

If(schleifenindex>0;Set(temp2;Last(FirstN(Kurse;1)).Kurs);; Set(temp3;LookUp(Kurse;Title=temp2));;
//Schüler zuweisen
Set(randomSchüler;FirstN(Shuffle(Filter(Schüler;gebKurs1=temp2 Or gebKurs2=temp2 Or gebKurs3=temp2 Or gebKurs4=temp2 Or gebKurs5=temp2 Or gebKurs6=temp2 Or gebKurs7=temp2 Or gebKurs8=temp2));temp3.maxTeilnehmer-temp3.actualTeilnehmer));;
ForAll(randomSchüler;If(ThisRecord.gebKurs1=temp2;Patch(Schüler;ThisRecord;{gebKurs1:""});If(ThisRecord.gebKurs2=temp2;Patch(Schüler;ThisRecord;{gebKurs2:""});If(ThisRecord.gebKurs3=temp2;Patch(Schüler;ThisRecord;{gebKurs3:""});If(ThisRecord.gebKurs4=temp2;Patch(Schüler;ThisRecord;{gebKurs4:""});If(ThisRecord.gebKurs5=temp2;Patch(Schüler;ThisRecord;{gebKurs5:""});If(ThisRecord.gebKurs6=temp2;Patch(Schüler;ThisRecord;{gebKurs6:""});If(ThisRecord.gebKurs7=temp2;Patch(Schüler;ThisRecord;{gebKurs7:""});If(ThisRecord.gebKurs8=temp2;Patch(Schüler;ThisRecord;{gebKurs8:""})))))))));;
Patch(Schüler;ThisRecord;{gebStunden:ThisRecord.gebStunden-temp3.Stunden};{zugStunden:ThisRecord.zugStunden+temp3.Stunden});;If(IsBlank(zugKurs1);Patch(Schüler;ThisRecord;{zugKurs1:temp2});If(IsBlank(zugKurs2);Patch(Schüler;ThisRecord;{zugKurs2:temp2});If(IsBlank(zugKurs3);Patch(Schüler;ThisRecord;{zugKurs3:temp2});If(IsBlank(zugKurs4);Patch(Schüler;ThisRecord;{zugKurs4:temp2});If(IsBlank(zugKurs5);Patch(Schüler;ThisRecord;{zugKurs5:temp2});If(IsBlank(zugKurs6);Patch(Schüler;ThisRecord;{zugKurs6:temp2});If(IsBlank(zugKurs7);Patch(Schüler;ThisRecord;{zugKurs7:temp2});If(IsBlank(zugKurs8);Patch(Schüler;ThisRecord;{zugKurs8:temp2}))))))))));;
//Schüler abwählen
Set(randomSchüler;Filter(Schüler;gebKurs1=temp2 Or gebKurs2=temp2 Or gebKurs3=temp2 Or gebKurs4=temp2 Or gebKurs5=temp2 Or gebKurs6=temp2 Or gebKurs7=temp2 Or gebKurs8=temp2));;
ForAll(randomSchüler;If(ThisRecord.gebKurs1=temp2;Patch(Schüler;ThisRecord;{gebKurs1:""});If(ThisRecord.gebKurs2=temp2;Patch(Schüler;ThisRecord;{gebKurs2:""});If(ThisRecord.gebKurs3=temp2;Patch(Schüler;ThisRecord;{gebKurs3:""});If(ThisRecord.gebKurs4=temp2;Patch(Schüler;ThisRecord;{gebKurs4:""});If(ThisRecord.gebKurs5=temp2;Patch(Schüler;ThisRecord;{gebKurs5:""});If(ThisRecord.gebKurs6=temp2;Patch(Schüler;ThisRecord;{gebKurs6:""});If(ThisRecord.gebKurs7=temp2;Patch(Schüler;ThisRecord;{gebKurs7:""});If(ThisRecord.gebKurs8=temp2;Patch(Schüler;ThisRecord;{gebKurs8:""})))))))));;Patch(Kurse;temp3;{actualTeilnehmer:temp3.actualTeilnehmer-1});;Patch(Schüler;ThisRecord;{gebStunden:ThisRecord.gebStunden-temp3.Stunden})));;

 

This code does it for the first course. I need a loop now to do it for every course, but it does not work then... Can anyone please help me with that? 

Categories:
I have the same question (0)
  • Mathelino Profile Picture
    2 on at

    the problem: when I type it in for every single loop walk through it does not work. I think then I have to many lines of code... then powerapp can not be saved anymore... and the code is just black without colors... I really need help it is very important to get this.... Thanks a lot!!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 414

#2
Valantis Profile Picture

Valantis 387

#3
timl Profile Picture

timl 344 Super User 2026 Season 1

Last 30 days Overall leaderboard