cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Compare two collections

Dear Powerusers community,

 

I have a screen where I can define the order of a list using up and down arrows by using a collection. By clicking on a "Save"-button the collection will update the SharePoint list with the defined order. Furthermore, I have a layover that will open when then user clicks on the "Back"-Button. What I would like to do now is have this layover only appear when the order has changed.

 

For this I created two collections on the button which navigates to the screen where you can define the order of the list. They both have the same items in them at the beginning, let's call them colOrder and colOrderCHECK (where this collection is used to compare). I would now like to compare both collections in order to see if colOrder = colOrderCheck. If they are the same I would like to go back to the other screen without prompting the layover when clicking on back, and logically, have the prompt open if the condition colOrder = colOderCHECK doesn't hold.

 

Is this possible? My function on the back button at this moment is: If(colOrder = colOderCHECK, Navigate(Homescreen,Screentransition.Fade),UpdateContext({varLayover:true}). Of course this doesn't work, there is an "invald argument type" error message on the "=". What are my options?

 

KR,

 

Chris

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Anonymousyou can't do a collection to collection comparison like that, but you could do a string to string.  So, perhaps look at Concat for the collections and then compare those two results.

   If(Concat(colOrder, YourColumn & ",") = (Concat(colOrderCheck, YourColumn & ","), ...

 

Hope that helps some.

_____________________________________________________________________________________
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

View solution in original post

8 REPLIES 8
RandyHayes
Super User III
Super User III

@Anonymousyou can't do a collection to collection comparison like that, but you could do a string to string.  So, perhaps look at Concat for the collections and then compare those two results.

   If(Concat(colOrder, YourColumn & ",") = (Concat(colOrderCheck, YourColumn & ","), ...

 

Hope that helps some.

_____________________________________________________________________________________
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

View solution in original post

CarlosFigueira
Power Apps
Power Apps

Currently, as you found out, there's no direct way to compare two collections in PowerApps (if you think this is a scenario that should be supported, please create a new feature request in the PowerApps Ideas board).

[After posting this I saw @RandyHayes solution, which is a lot simpler; will leave this one here for completeness, but if his solution works for you, I'd definitely go with it]

There is a way to compare two collections, which is not very direct but may work for your scenario. Imagine that your two collections are called 'col1' and 'col2', and the column that you want to compare is called 'Value'. This expression will return 'true' if the collections are the same, and 'false' otherwise (for collections with up to 16 records):

CountRows(col1) = CountRows(col2) And
Sum(
    ForAll(
        RenameColumns(FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], CountRows(col1)), "Value", "index"),
        If(Last(FirstN(col1, index)).Value = Last(FirstN(col2, index)).Value, 0, 1)),
    Value) = 0

The first line compares the sizes of the collections; if they're different than we know that the collections are different. The second part of the expression iterates through all items in both collections, in order, returning 0 if they're the same or 1 if they're different. Then all those values are Sum'ed up, and if the result is 0, then all items are the same.

Hope this helps!

Anonymous
Not applicable

@RandyHayes  This solution works ! Thanks a lot 🙂

@CarlosFigueira Thank you as well for your time! will keep your solution in mind for the future!

Hi @RandyHayes , 

 

I like your solution for checking a single column between two Collections for changes. Ideas for checking all columns between two Collections?

 

I've had to add a column called "lastSaved" or the like; set a variable to its initial state OnStart/OnVisible; then update this column whenever a change is made to any column; set another variable, then compare the two throughout the users experience to control things like Submit button, progress bars, etc. 


Would love a simpler way to determine state changes between data source and user input!


Cheers!

Hello Sir, @RandyHayes 

By using your formula, I have compared two person fields in two different SP Lists,

 

but I want to show a Number Column field from List B in a Label >  Text.

I am getting an Error

my Code: 

 

If(Concat(LeaveRequests, EmployeeName.Email & ",") = (Concat(EmployeeLeaveBalance, EmployeeName.Email & ",")),EmployeeLeaveBalance.'Annual Balance',"16")
    

 

 I am getting If has invalid arguments, where EmployeeLeaveBalance is List B and Annual Balance is a Number Column in this list.

Help

@MH3 

I'm not entirely sure what you are trying to compare with your two Concat's.  With that formula, you are going to have a string of ALL of the EmployeeEmails from LeaveRequests compared to a string of ALL of the EmployeeEmails from EmployeeLeaveBalance.

In order for that to ever be true, you will have to pretty much have identical lists.  I can't imagine that would ever be true.

As for your specific error - you are then trying to display a number from AnnualBalance, but you are specifying the entire list and the column as the reference.  That will not work (and thus your error).  You need to reference either a sum, or a specific record to get an actual value.  This would normally be done with a filter, lookup, sum, or other table based function.  But I have no idea what the criteria would be since I am not understanding your comparison.

_____________________________________________________________________________________
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

Dear Sir, @RandyHayes 

I'll clarify you my problem.

 

actually I am working over a leave request application and I wanted to show Leave Balances of a employee who requested a leave type lets say Annual, and in the Annual Balance, I want to compare either that employee who requested the leavetype is in that EmployeeLeaveBalance list or not, if its there then show the Annual Balance Column  which is 14  and its a Number Column.


While I have another List called LeaveRequests which is List A, in which I am storing the User email who Requested in EmployeeName (which is a Person Column), The Manager Email which he chosen in Approver Column, The Start Date, End Date and the Days Requested and Description.

So, I wanted to show the Annual Balance for that particular employee. 

have you understood my requirement?

iselghaz-mstf
Microsoft
Microsoft

 The answer in the below article worked for me, creating 2 collections and then using the filter()

https://powerusers.microsoft.com/t5/Building-Power-Apps/Compare-two-collections-and-list-only-no-mat...

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (91,272)