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
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,723)