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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Unable to create a Col...
Power Apps
Unanswered

Unable to create a Collection inside a Switch sentence

(0) ShareShare
ReportReport
Posted on by 9

Hi Comunity,

 

I need to create a Collection dinamically depending on the value of a variable. The name of the collection must be always the same because after I show the content in a table but the data source must be different: This is the code I'm trying to use:

 

Switch(
Last(Linea).Value;
      "Renewables"; ClearCollect(Plani; PlaniRen);
      "Corporate"; ClearCollect(Plani; PlaniCorp);
      "Liberalized"; ClearCollect(Plani; PlaniLib);
      "Networks"; ClearCollect(Plani; PlaniNet)
);;

 

If I use only one row, the code works fine but once I add additional line, the system shows me an error in the ClearCollect sentence (Invalid arguments).

 

Does somebody know how to manage?

 

Thanks in advanced,

Edorta

I have the same question (0)
  • v-jefferni Profile Picture
    on at

    Hi @Edorta ,

     

    The issue is not relate to the Switch statement but to the collection. When you first time use Collect or ClearCollect to create a collection, the data structure is determined and relies on the collection name, which means if you want to update the collection elsewhere you need an exact same data structure.

     

    I assume the four data tables will have columns with different names, so the collection columns will be "dynamic" which is not allowed. To solve this issue, you could use ShowColumns and RenameColumns functions to artificially rename the columns to be totally same:

    Switch(
     Last(Linea).Value;
     "Renewables"; ClearCollect(Plani; RenameColumns(ShowColumns(PlaniRen; "Column1.1";"Column2.1";"Column3.1");"Column1.1";"Column1.2";"Column2.1";"Column2.2";"Column3.1";"Column3.2");
     "Corporate"; ClearCollect(Plani; RenameColumns(ShowColumns(PlaniCorp; "Column1.1";"Column2.1";"Column3.1");"Column1.1";"Column1.2";"Column2.1";"Column2.2";"Column3.1";"Column3.2");
     "Liberalized"; ClearCollect(Plani; RenameColumns(ShowColumns(PlaniLib; "Column1.1";"Column2.1";"Column3.1");"Column1.1";"Column1.2";"Column2.1";"Column2.2";"Column3.1";"Column3.2");
     "Networks"; ClearCollect(Plani; RenameColumns(ShowColumns(PlaniPlaniNet; "Column1.1";"Column2.1";"Column3.1");"Column1.1";"Column1.2";"Column2.1";"Column2.2";"Column3.1";"Column3.2");
    );;

    ShowColumns to retrieve all the columns you need from each data source, RenameColumns to rename them as same columns.

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Verified answer
    Edorta Profile Picture
    9 on at

    Thanks Jeffer,

    I ensured that the estructure of the different Excel files that act as sources for collection filling are exactly the same (I copied the headers) but the error still remains.

     

    Finally I decided to create 5 different collections and make the visualization of the correct one dynamic using a Switch sentence.

     

    Best Regards,

    Edorta

     

  • v-jefferni Profile Picture
    on at

    Hi @Edorta ,

     

    If you renamed only the display names of the columns, this may be the reason. Need to rename list columns in list settings.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard