Close menu

πŸͺ„πŸˆβ€β¬› TnT #6 🧨

Table of contents

Unique and Distinct

Unique or Distinct, are synonyms essentially meaning only one of each.

But what does this mean for the Power Platform?

Say I have a list, or an array, of values:

[1, 2, 3, 3, 4, 5, 5, 5, 6, 7]

If I am in a Power Apps Canvas App, it’s easy-peasy to get the unique values of this list using the Power Fx function Distinct().

A screenshot of a code snippet showing a function Concat(Distinct([array of numbers]), .Value, ", ") being used in a script editor, with the distinct function highlighted, demonstrating the process of removing duplicates from an array and joining the elements into a string.
Power Fx function, Distinct(), being used to generate a unique list of numbers.

But what about when you’re in Power Automate? If you just look through the list of all the available function names for Collections, there is not a Distinct() function readily available…

The Power Automate expression builder user interface displaying a list of functions for manipulating collections, such as 'contains', 'length', 'sort', 'reverse', and others. The description of each function indicates how to use the expression to access, convert, and compare values.
The Power Automate expression builder User Interface displaying a list of functions for manipulating collections.

But fear not, because the union() function will generate a distinct list of values! (You just have to trick it a little…🀫)

Screenshot of the Power Automate expression builder, specifically displaying the expression: union(body('Select'), body('Select')). 
Each use of body('Select') is highlighted, signifying an importance.
The Power Automate expression builder, displaying the expression: union( body(‘Select’), body(‘Select’) )

Basically, use your single array for both required arguments in the function. This works with numbers, text, and even records/objects (like items from a SharePoint List πŸ€”πŸ’‘).

Power Automate Exception

However, be aware that the union() function currently does NOT work as expected when using the new Power Automate Flow designer. In this case, it simply joins both lists of values together, meaning you now have a list with double the number of items as before! 😬

Switching to the Classic Flow designer does not easily fix this buggy behavior either. The bug persists even after you swap designers. This requires that you completely remove the action using the union() function, save, and refresh. Then you can add the action back in to use it as intended (for returning a distinct list of values).

I hope this information is helpful to someone else out there!

0 0 votes
Post Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x