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 / ClearCollect not retur...
Power Apps
Unanswered

ClearCollect not returning all records in a Switch or If statement

(0) ShareShare
ReportReport
Posted on by 19

Hi, i have a small Sharepoint list (<500 items including the hidden system columns). I'm trying to load a specific Sharepoint list based on a dropdown box choice into a collection using ClearCollect. 

It appears there is a bug (unless I'm missing something) in that a number of columns do not get loaded into the collection when the ClearCollect is called from within a Switch or If statement, with Switch and If (I've tried both) determining the correct Sharepoint list to load based on the dropdown box selection. 

If I do a ClearCollect on any one of the Sharepoint lists outside of the If/Switch logic (ie. dropdown choice has no effect) then all columns load fine.

Am I missing something or is this a bug? I've tried closing Powerapps and restarting, removing and re-connecting the Sharepoint lists and disabled the "explicit column selection" setting.

PowerApps ver 3.21081.49.

 

Sample Code:

//works fine - all columns retrieved and in the Units collection

ClearCollect(Units,'Conversion Table - xyz')

//does not work fine - some columns are missing in the units collection

If(dropdownName.Selected.Value="xyz",ClearCollect(Units,'Conversion Table - xyz'))

 

 

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Richierich81 

    Assuming your the source table is Units and has a column that contains the value "xyz",

    ClearCollect('Conversion Table - xyz', Filter(
     Units, columnwithxyz = Dropdown.Selected.Value
     )
    )
  • Richierich81 Profile Picture
    19 on at

    Hi, thanks for getting back to me so quick. I should have mentioned 'Conversion Table - xyz' is the name of a Sharepoint list.  Units is the collection - i'm trying to load the Sharepoint list into the Units collection so I can have one gallery rather than 5 identical galleries - too much development time and inefficient...

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Richierich81 

    OK,

     

    ClearCollect(Units,
     Filter(
     'Conversion Table - xyz', columnwithvalue= DropdownName.Selected.Value
     )
    )

     

     I am not sure why you need a collection though.  a simpler statement would be to make the Items property of the gallery. 

     

    Filter(
     'Conversion Table - xyz', columnwithvalue= DropdownName.Selected.Value
    )
     

    This formula is delegatable whereas Collect and ClearCollect are not.

     

  • Richierich81 Profile Picture
    19 on at

    Hi, apologies I've not been clear!

    So, I have an x/y table to do some conversions (ie. match a row against column to find a unit conversion). I have different materials with different properties, hence the requirement for different SP lists. 

    So after playing, it looks like calling a ClearCollect within a switch seems to create a collection that auto includes a column with the name of the Switch condition (?!).

     

    If i did the clearcollect outside of  switch, its absolutely fine. How weird?! 

     

    //Code thats not working

    Switch(
    dd_MaterialSelector.Selected.Value,
    "xyz",
    ClearCollect(Units,'Conversion Table - xyz'),
    "abc",
    ClearCollect(Units,'Conversion Table - abc'),

    "def",
    ClearCollect(Units,'Conversion Table - def'),

    ClearCollect(Units,'Conversion Table - def')

    )

  • Verified answer
    Richierich81 Profile Picture
    19 on at

    OK - how odd. Definitely a bug in switch/if! It seems that calling ClearCollect within the switch/if statement appears to refer to the "internal name" of a sharepoint list column - which is the name given to the column when it was first created. I had since changed it, but hadn't put two and two together. I've now created a new column with the column name i want, copied data over, and deleted the original column. 

    My switch function/clearcollect now working perfectly, and i only have one gallery that dynamically changes.....

    However, an afternoon swallowed up figuring that one out....

    Thanks @Drrickryp for trying to work me out, looks like I resolved myself in the end, but if anyone else has this issue, its the internal name... grr.

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