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
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.
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
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.
WarrenBelz
85
Most Valuable Professional
Michael E. Gernaey
57
Super User 2025 Season 1
mmbr1606
55
Super User 2025 Season 1