Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Problem creating a nested collection

(0) ShareShare
ReportReport
Posted on by 331
Hello all,
 
I need to create a nested collection of teachers' schedules and display them in a nested gallery.
I've been trying to create my collection for over 2 days now, without success:
The idea is as follows:
I have a sharepoint list with a ProfName, DayNumber, PeriodNumber and Class column.
In my application I have a choice list to search for a teacher. When my choice list is modified, I trigger the event and fill my Occupation collection as follows:  
 Create a collection of 5x13 elements (5 days and for each 13 teaching periods).
For each item in my suite, I search my sharepoint list for the day number (Value1 in my list), period number and teacher name.
Here's where I'm at, without success:
 
ClearCollect(
    TimeTable;
    ForAll(
        [1; 2; 3; 4; 5]; // Boucle sur les jours de la semaine (1 = Lundi; 5 = Vendredi)
        With(
                DayNumber: Value; // Capture la valeur du jour dans une variable de contexte
                DayName: Switch(
                    Value;
                    1; "Lundi";
                    2; "Mardi";
                    3; "Mercredi";
                    4; "Jeudi";
                    5; "Vendredi"
                )
            };
            {
                Day: DayNumber;
                JourNom: DayName;
                ListPeriodes: ForAll(
                    Sequence(13); // Boucle sur les périodes (de 1 à 13)
                    With(
                        {
                            ClasseValue: LookUp(
                                SharepointList;
                                DayNumber = Day && PeriodNumber = Value; // Utilisation de JourValeur et PeriodeValeur
                                Class
                            )
                        };
                        {
                            Periode: Value;
                            Matiere: Blank();
                            Classe: If(IsBlank(ClasseValue); Blank(); ClasseValue);
                            Remplacant: Blank();
                            Annotation: Blank()
                        }
                    )
                )
            }
        )
    )
)
 
The first error message says : DayNumber is invalid because unknown ..

Here's the place where my collection should be used :
 
So any idea is very welcomed :)
  • Verified answer
    forstera Profile Picture
    331 on at
    Problem creating a nested collection
    According to this example , it seems my variables should be declared in { }
     
    With({parentRecord:LookUp(colCustomerOrder, Firstname="Sally")},
         With({orderTable:parentRecord.Orders},
              UpdateIf(orderTable, Product="DVDs", {Quantity:5});
              Patch(colCustomerOrder, parentRecord, {Orders:orderTable})
         )
    )
    So I tried to modify the structure like this and it seems to work ..
    ClearCollect(
        EmploiDuTemps;
        ForAll(
            [1; 2; 3; 4; 5];
            With(
                {
                    DayNumber: Value;
                    DayName: Switch(
                        Value;
                        1; "Lundi";
                        2; "Mardi";
                        3; "Mercredi";
                        4; "Jeudi";
                        5; "Vendredi"
                    )
                };
                {    Periods: ForAll(
                        Sequence(13; 1; 1);
                        With(
                            {
                                ClasseValue: LookUp(
                                    ListeHoraires;
                                    Colonne1 = "TR_NAN" &&
                                    Colonne4 = DayNumber &&
                                    Colonne5 = Value;
                                    Colonne3
                                )
                            };
                            {
                                Periode: Value;
                                Classe: If(IsBlank(ClasseValue); Blank(); ClasseValue);
                                Matiere: Blank();
                                Remplacant: Blank();
                                Annotation: Blank()
                            }
                        )
                    );
                    Day: DayNumber;
                    JourNom: DayName
                }
            )
        )
    )
     
     
  • mmbr1606 Profile Picture
    13,191 Super User 2025 Season 1 on at
    Problem creating a nested collection
    Well then u simply need to Update your Code with the modification u made
  • forstera Profile Picture
    331 on at
    Problem creating a nested collection
    yes, I used it and it seems to have worked at one point (at least this part) but I've made so many changes to my structure that I don't know when ;sorry
     
    Here's the complete structure :
     
  • mmbr1606 Profile Picture
    13,191 Super User 2025 Season 1 on at
    Problem creating a nested collection
    i guess it does say
     
     
    daynumber is not recognized? didnt you use this in your original code too?
     
     
    cheers
  • forstera Profile Picture
    331 on at
    Problem creating a nested collection
    Dear mmbr1606,
     
    Thanks very much for your proposition. so I pasted it to my application but I get the following error in the Lookup function :
    (I had to change the columns name to fit my sharepoint list)
     
     
    Here's my sharepoint list :
     
     
    I get some troubles with my dropBox so, for the while, I fix a value to test the whole structure :
     
     
    But I get that :
     
     
    DayNumber is unknown..
     
    Thanks very much for your help :)
  • Verified answer
    mmbr1606 Profile Picture
    13,191 Super User 2025 Season 1 on at
    Problem creating a nested collection
    hey
     
     
    can u try this approach:
    ClearCollect(
        TimeTable,
        ForAll(
            [1, 2, 3, 4, 5],
            With(
                {
                    DayNumber: Value,
                    DayName: Switch(
                        Value,
                        1, "Lundi",
                        2, "Mardi",
                        3, "Mercredi",
                        4, "Jeudi",
                        5, "Vendredi"
                    ),
                    Periods: ForAll(
                        Sequence(13, 1, 1),
                        With(
                            {
                                ClasseValue: LookUp(
                                    SharePointList,
                                    ProfName = DropdownTeacher.Selected.Value &&
                                    DayNumber = DayNumber &&
                                    PeriodNumber = Value,
                                    Class
                                )
                            },
                            {
                                Periode: Value,
                                Classe: If(IsBlank(ClasseValue), Blank(), ClasseValue),
                                Matiere: Blank(),
                                Remplacant: Blank(),
                                Annotation: Blank()
                            }
                        )
                    )
                },
                {
                    Day: DayNumber,
                    JourNom: DayName,
                    ListPeriodes: Periods
                }
            )
        )
    );
    
    if it worked please mark as verified answer,
     
     
    cheers

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1