cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ogend
Advocate I
Advocate I

Distinct values from two strings

Hi Power Automate Gurus, 

 

I have two string variables  (not arrays) with email addresses separated by semicolon, is there a way to create a string with distinct values only? 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Super User
Super User

Yes, you can use the Split() and Union() functions to get a list of unique email addresses:

Snag_5943b03.png

The union() function in the Compose Unique action returns an array of distinct email addresses. The expression is:

 

union(split(variables('varList1'),';'),split(variables('varList2'),';'))

 

The Split() function splits the List string at the ';' character and produces an array for List1 and List2. The Union() function is then used to get unique values from the two arrays.

 

The union() function returns an array. We can use the join() function to get a string:

Snag_604ffba.png

The expression is:

 

join(outputs('Compose_Unique'),';')

 

 

Example lists containing email addresses:

ekarim2020_0-1642936234405.png

 

Runtime output of the Compose Unique action:
union(split(variables('varList1'),';'),split(variables('varList2'),';'))

Snag_5957076.png

 

This is the runtime output of the expression for the Compose action
join(outputs('Compose_Unique'),';')

name1@domain.com;name2@domain.com;name3@domain.com;name4@domain.com;name5@domain.com;name6@domain.com;name7@domain.com;name8@domain.com;name9@domain.com;name10@domain.com;name11@domain.com;name12@domain.com;name13@domain.com;name20@domain.com;name21@domain.com;name25@domain.com;name26@domain.com


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

2 REPLIES 2
ekarim2020
Super User
Super User

Yes, you can use the Split() and Union() functions to get a list of unique email addresses:

Snag_5943b03.png

The union() function in the Compose Unique action returns an array of distinct email addresses. The expression is:

 

union(split(variables('varList1'),';'),split(variables('varList2'),';'))

 

The Split() function splits the List string at the ';' character and produces an array for List1 and List2. The Union() function is then used to get unique values from the two arrays.

 

The union() function returns an array. We can use the join() function to get a string:

Snag_604ffba.png

The expression is:

 

join(outputs('Compose_Unique'),';')

 

 

Example lists containing email addresses:

ekarim2020_0-1642936234405.png

 

Runtime output of the Compose Unique action:
union(split(variables('varList1'),';'),split(variables('varList2'),';'))

Snag_5957076.png

 

This is the runtime output of the expression for the Compose action
join(outputs('Compose_Unique'),';')

name1@domain.com;name2@domain.com;name3@domain.com;name4@domain.com;name5@domain.com;name6@domain.com;name7@domain.com;name8@domain.com;name9@domain.com;name10@domain.com;name11@domain.com;name12@domain.com;name13@domain.com;name20@domain.com;name21@domain.com;name25@domain.com;name26@domain.com


Ellis
____________________________________
If I have answered your question, please mark the post as Solved.
If you like my response, please give it a Thumbs Up.

ogend
Advocate I
Advocate I

@ekarim2020 Thanks a lot, this is superhelpful!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,154)