cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

7 REPLIES 7
Highlighted
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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

Highlighted
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!

Highlighted
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!

Highlighted

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!

Highlighted

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

Highlighted

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Highlighted

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?

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (10,121)