cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

Collect, AddColumns, UpdateIf

I'm having some difficulty with the pattern here. Looking for guidance. 

Scenario:

- Collection may originate on-device or from Sharepoint list

- If originating on-device, there is no unique identifier (the auto ID column is applied when the record is Patched to Sharepoint)

- I want to use AddColumns to create the unique ID when originating on-device

AddColumns(
Collect(colActionReport,
    {
        GUID0: varGUID,
        1: Blank(),
        2: Blank(),
        3: Blank()
    }
),"localID", varCounter + 1)

- User then proceeds to populate a colActionReport record using dropdowns/etc.

- OnChange of each dropdown/etc, I'm using UpdateIf to "patch" in records (Can't use Patch here because sometimes colActionReport originates from Sharepoint and I can't Patch a collection originating from Sharepoint, only UpdateIf.

UpdateIf(colActionReport, localID = ThisItem.ID,
    {
        1: test.Selected.Value
    }
)

- Unfortunately, I can't use the AddedColumn "localID". Its not recognized.

 

How do I reference a column added with AddColumns?


Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @ericonline ,

Based on the issue that you mentioned, I think you have some misunderstanding on the AddColumns function.

 

Actually, the result the AddColumns function returned is an temporary table with the transform applied, the underlying table (on your side, it is colActionReport) would not be changed.

 

More details about AddColumns function, please check the following article:

AddColumns function

 

On your side, please consider modify your formula as below:

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: CountRows(colActionReport) + 1 /* <-- Calculate Row Index Value */
}
)

Or

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: Blank() /* <-- Row Index Value */
}
);
Patch(
colActionReport,
Last(colActionReport),
{
localID: varCounter + 1
}
)

 

Then modify the formula within the OnChange property of the Dropdown box to following:

UpdateIf(
colActionReport,
localID = ThisItem.ID, { 1: test.Selected.Value } )

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
RezaDorrani
Dual Super User II
Dual Super User II

Hi @ericonline 

 

AddColumns(
Collect(colActionReport,
    {
        GUID0: varGUID,
        1: Blank(),
        2: Blank(),
        3: Blank()
    }
),"localID", varCounter + 1)

replace with

Collect(colActionReport, { GUID0: varGUID, 1: Blank(), 2: Blank(), 3: Blank() };

ClearCollect(colActionReportNew, AddColumns(colActionReport,"localID",varCounter + 1));

 

This will create a new collection with the added column - also please note the new column value will be same for all the rows

 

 

 

UpdateIf(colActionReport, localID = ThisItem.ID,
    {
        1: test.Selected.Value
    }
)

 update to below (only change is collection name)

 

UpdateIf(colActionReportNew, localID = ThisItem.ID,
{
1: test.Selected.Value
}
)

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you for the guidance @RezaDorrani .

I opted to remove the ability to create collections on-device and instead use the Sharepoint-created ID column as the unique identifier. 

There are some UX impacts as user must wait for the server round trip, but overall, a bit easier for me to move forward with. 
Now I can use:

UpdateIf(colActionReport, ID = ThisItem.ID,
    {
        1: Test.Text
    }
)
v-xida-msft
Community Support
Community Support

Hi @ericonline ,

Based on the issue that you mentioned, I think you have some misunderstanding on the AddColumns function.

 

Actually, the result the AddColumns function returned is an temporary table with the transform applied, the underlying table (on your side, it is colActionReport) would not be changed.

 

More details about AddColumns function, please check the following article:

AddColumns function

 

On your side, please consider modify your formula as below:

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: CountRows(colActionReport) + 1 /* <-- Calculate Row Index Value */
}
)

Or

Collect(
colActionReport,
{
GUID0: varGUID,
1: Blank(),
2: Blank(),
3: Blank(),
localID: Blank() /* <-- Row Index Value */
}
);
Patch(
colActionReport,
Last(colActionReport),
{
localID: varCounter + 1
}
)

 

Then modify the formula within the OnChange property of the Dropdown box to following:

UpdateIf(
colActionReport,
localID = ThisItem.ID, { 1: test.Selected.Value } )

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,870)