cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Powerslave
Frequent Visitor

Collection for selected items from SharePoint list

Hi,

 

I have SharePoint list called Accounts. List have columns AccountName (Single line of text) and AccountDescription (Multiple line of text).

I try to create collection from Accounts -list for the Data Table. Collection should have multiple accounts from Accounts -list. Account IDs are coming from another list and can vary based on item (for example: ID=8 Or ID=9 Or ID=10 Or ID=11 Or ID=12 Or ID=13 Or ID=14 Or ID=15 Or ID=16).

 

I can create collection by manually typing the IDs to If-statement. See code sample below.

 

 

Clear(colAccounts);
ForAll(
    Accounts,
    If(
        ID=8 Or ID=9 Or ID=10 Or ID=11 Or ID=12 Or ID=13 Or ID=14 Or ID=15 Or ID=16,
        Collect(
            colAccounts,
            {ID:ID,AccountName:AccountName,AccountDescription:AccountDescription}
        )
    )
)

 

 How could I create collection when IDs are changing dynamically based an selection from another list list item? 

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Super User
Super User

Hi @Powerslave 

 

Interesting, Good findings. Np. We can split the variable and should works. I just tested as well.

 

With(
    {_Item: 'SPListName'},
    Filter(
        _Item,
        ID in (Split(VariableAccountIds,","))
    )
)

 


Thanks,
Stalin - Learn To Illuminate

View solution in original post

6 REPLIES 6
StalinPonnusamy
Super User
Super User

Hi @Powerslave 

 

Is it possible to get ID's from another list like "8,9,10" instead of ID=8 Or ID=9 Or ID=10?

 

If yes and this output is for the Data table then we don't need collection. Set the Items property of the Data table to

With(
    {_Item: 'SPListName'},
    Filter(
        _Item,
        ID in (VariableAccountIDs)
    )
)

 

If you get Account ID's like ID=8 Or ID=9 Or ID=10 then we need to manipulate the string to get "8,9,10"

 


Thanks,
Stalin - Learn To Illuminate

StalinPonnusamy
Super User
Super User

Hi @Powerslave 

 

If we get Account Id's like "ID=1 Or ID=2 Or ID=13 Or ID=11 Or ID=12 Or ID=13 Or ID=14 Or ID=15 Or ID=16" then we can do like

With(
    {_Item: 'External User'},
    Filter(
        _Item,
        ID in (Substitute(varAccountIDs," Or ",","))
    )
)

 

 Nore: Replace "varAccountIDs"

 

Hi @StalinPonnusamy Yes, I can get ID's and manipulate them as a string. I will try your suggestion and let you known if that works. Thanks!

Hi @StalinPonnusamy.
Your suggestion works, but if I have for example following IDs 

Set(VariableAccountIds,"10,11,12")

code 

With(
    {_Item: 'SPListName'},
    Filter(
        _Item,
        ID in (VariableAccountIDs)
    )
)

returns Accounts with IDs 1,2,10,11 and 12. This is because of using in-operator.
How could I get exactly Accounts with Ids 10,10 and 12?

StalinPonnusamy
Super User
Super User

Hi @Powerslave 

 

Interesting, Good findings. Np. We can split the variable and should works. I just tested as well.

 

With(
    {_Item: 'SPListName'},
    Filter(
        _Item,
        ID in (Split(VariableAccountIds,","))
    )
)

 


Thanks,
Stalin - Learn To Illuminate

Hi @StalinPonnusamy 

Yes, splitting the variable works as expected. Now I can get exactly Accounts with Ids 10,10 and 12 by using variable Set(VariableAccountIds,"10,11,12").

With(
    {_Item: 'SPListName'},
    Filter(
        _Item,
        ID in (Split(VariableAccountIds,","))
    )
)

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,254)