cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonathanO
Advocate II
Advocate II

Unable to remove column from collection - ClearCollect from a list box control adding extra column

I have a list box that contains vehicles.  The app will allow users to determine which vehicles were damaged in an accident.  The listbox will show as list of VIN numbers and user can select one or more vehicles.  

 

When the user presses save button, the app needs to update the SQL table table column AccidentID for each vehicle.  The AccidentID variable is already populated by the time this process takes place.

 

After trying many things, I thought @mr-dang's solution in this post would be best:

 

https://powerusers.microsoft.com/t5/General-Discussion/Patch-a-Collection/td-p/9329/page/3

 

Since I do not need to worry about creating records, only updating, I modified his solution to remove the part of the dorumla that creates a record if it doesn't already exist in the SQL table.

However, the issue I am running into is that when I ClearCollect() from the ListBox control, I have all of the expected columns from the SQL table (the items of the listbox control are from a SQL data source).  However, there is one extra column called "Value". 

I suspect that because of this, the Patch fails since the columns are not the same between the datasource and the collection.  In fact, a red squiggle shows under the Patch formula and ther error says "The specified column 'Value' not found".

I thought I could just remove the column, however, when I try to use DropColumns(VehicleDamages,"Value") I get an error that the column "Value" does not exist.  Yet, if I go to View > Collections > VehicleDamages, I clearly see a "Value" column.

 

So it seems that Patch() sees the Value column and I get an error, but DropColumns() does not see the column.

Any idea on how to either remove this column or how to update a column in SQL table for the records selected in a List Box?

 

Example:

 

1. Here is result of ClearCollect(VehicleDamages, VehiclesListBox.SelectedItems )  The ListBox items are from SQL table.  There is not a Value column in the SQL table

PatchIssue1.PNG

 

 

 

2. Here is the error if I try to drop the column:

PatchIssue2.PNG

 

 

3. Here is the formula and error from the Patch() function (formula adapted from mr-dang post):

 

Formula:

ForAll(RenameColumns(VehicleDamages,"ClaimVehicleID","CID"),
Patch('SQLTable',First(Filter('SQLTable',ClaimVehicleID=CID)),
First(Filter(VehicleDamages,ClaimVehicleID=CID))
)
)

Error:

InkedPatchIssue3_LI.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

The Value is a column that comes from the ListBox selection - in addition to the other columns from the data source you're getting it. I don't know why you cannot drop that column - it's likely a bug, which I'll file with the team to fix.

 

As a workaround, you can select all other columns in the data source (using the ShowColumns function) and explicitly select the columns that exist on the database table:

ClearCollect(
    VehicleDamages,
    ShowColumns(
        VehiclesListBox.SelectedItems,
        "AuctionProceeds",
        "ClaimID",
        "ClaimVehicleID",
        "Color",
        "EstimatedVehicleDamage",
        "FeesCharged",
        ...
    )
)

With this you should be able to patch from the items in the collection.

View solution in original post

8 REPLIES 8
v-monli-msft
Community Support
Community Support

Hi @jonathanO,

 

How did you create this Value column? From SQL server data? What if you try to change to other columns in the collection to have a test? Will the same error occur on other columns or just this one?

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @jonathanO,

Have you already tried to adress the column 'value' by its original name from the database?

CarlosFigueira
Power Apps
Power Apps

The Value is a column that comes from the ListBox selection - in addition to the other columns from the data source you're getting it. I don't know why you cannot drop that column - it's likely a bug, which I'll file with the team to fix.

 

As a workaround, you can select all other columns in the data source (using the ShowColumns function) and explicitly select the columns that exist on the database table:

ClearCollect(
    VehicleDamages,
    ShowColumns(
        VehiclesListBox.SelectedItems,
        "AuctionProceeds",
        "ClaimID",
        "ClaimVehicleID",
        "Color",
        "EstimatedVehicleDamage",
        "FeesCharged",
        ...
    )
)

With this you should be able to patch from the items in the collection.

View solution in original post

This worked, thank you @CarlosFigueira

Is there any solution on this problem since the DoropColumns command still doesn't work;

 

ClearCollect(DataTmp, DataFiltered);
DropColumns(DataTmp,"CODICE")

 

after then the collection DataTmp still have the column "CODICE"... why?

 

 

The DropColumns function doesn't change the table that is passed to it; instead it returns a table without that column. Take a look at the documentation for that function for more details.

For example, if you want DataTmp to have all columns in the DataFiltered collection except "CODICE", then you can use the following expression:

ClearCollect(DataTmp, DropColumns(DataFiltered,"CODICE"))

Yes, it works correctly as you suggested. Thanks.

Is there a fix for this behaviour yet with the phantom Value column? I still get the same issue 3 years later when trying to drop the column 'Value' which gets auto-created when you add a list box to the form, where it just says the column doesn't exist.

 

I have several hundred columns in the collection and don't really want to manually have to type them all out for which ones to include when I should just be able to choose the one column to exclude using DropColumns. ...

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,079)