cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
David283
Helper II
Helper II

Filtering from another Collection inside a CountRows function

I am building 2 collections and populating them from SharePoint lists.  After building and populating the first SharePoint list (ColOrderItemised), I then build the second one (ColOrdersList) with an additional 'AddColumns' function to add an addition column that counts the number of rows in the first collection that contain a given value.

 

I have managed to get everything I mentioned above working, the only problem is the 'CountRows' function is returning a wrong number.  It seems to be counting all the rows, not the rows that should result from my filter.

 

My code  (this is in the 'OnVisible' for the screen) = 

 

ClearCollect(ColOrderItemised,
      Filter(OAOrderItemisedList, Purchased = false)
)
;
ClearCollect(ColOrdersList,
    AddColumns(         
        Filter(OAOrdersList, OrderComplete = false),
        "ItemCount" , CountRows(Filter(ColOrderItemised, OrderID = ThisRecord.OrderID))
    )
)

 

 

The filter "Filter(ColOrderItemised, OrderID = ThisRecord.OrderID)" is comparing the 'ItemID' fields from 2 different collections. The first is the 'ColOrderItemised' collection which will have multiple records containing the same OrderID, and the second collection is the one being created here, 'ColOrdersList'.  For this second collection, the OrderID will be unique.

 

As a test, I replace the second part of the filter with a number ( replaced 'ThisRecord.OrderID' with '6' ) .  And that worked, it counted the correct number of rows.

 

Can anyone help me figure out why my filter isn't working?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@David283 

Your ThisRecord in your formula is going to refer to the record of that filter...not the one you expect.

Please consider changing your Formula to the following:

ClearCollect(ColOrderItemised,
      Filter(OAOrderItemisedList, Purchased = false)
)
;
ClearCollect(ColOrdersList,
    AddColumns(         
        Filter(OAOrdersList, OrderComplete = false) As _item,
        "ItemCount" , CountRows(Filter(ColOrderItemised, OrderID = _item.OrderID))
    )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User
Super User

@David283 

Your ThisRecord in your formula is going to refer to the record of that filter...not the one you expect.

Please consider changing your Formula to the following:

ClearCollect(ColOrderItemised,
      Filter(OAOrderItemisedList, Purchased = false)
)
;
ClearCollect(ColOrdersList,
    AddColumns(         
        Filter(OAOrdersList, OrderComplete = false) As _item,
        "ItemCount" , CountRows(Filter(ColOrderItemised, OrderID = _item.OrderID))
    )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

That fixed it, thank you very much.  Didn't know about 'As', reading more about that now.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

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