web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Can't get this working...
Power Apps
Answered

Can't get this working: remove duplicate lines from text string

(0) ShareShare
ReportReport
Posted on by 37

I tried Monitor but it doesn't show variable values.

 

I have a string of lines (_emailBody) that might include duplicates (because users). So to remove the duplicates I have:


Set(_lines, Split(_emailBody, Char(10)));
Set(_distinct, Distinct(_lines, Text));
Set(_concated, Concat(_distinct, Char(10)));
Set(_emailBody, _concated);

 

But it doesn't work, and I have no idea why not because I can't see what any of it is actually doing because there is no debugger. Trace() doesn't help either, because these are objects and I don't know how to convert them to strings.

 

This would take like 30 seconds in C# but in PowerApps I'm an hour into it and completely stuck. 

Categories:
  • AaronKnox Profile Picture
    514 Super User 2024 Season 1 on at

    Hi @gerrysr6omfg ,

    It seems you were close to the solution.  Add this code to a button, play the app, click the button, then close the player and highlight _emailBody.  This will let you know the data type and provide a mini preview:

    Set(_emailBody, 
    "User Generated Data Line1
    User Generated Data Line2
    User Generated Data Line3
    User Generated Data Dupe
    User Generated Data Dupe
    User Generated Data Line4
    User Generated Data Line5"
    )

     

    Capturef4.PNG

     

    Then add this code in another button, no need to play, highlight the code to see the outcome:

    Distinct(Split(_emailBody, Char(10)),Result)

    Capturef5.PNG

     

    You might ask, what's going on here with 'Result'?  Both Split() and Distinct() return a single column table with Result as the name of the column. 

     

    Keep in mind that Distinct() is GroupBy()'s sidekick.  Complex distinct/grouping requires GroupBy, but from what you mentioned Distinct will probably work OK for this scenario.

     

    The GroupBy formula, to do the exact same thing, is:

    GroupBy( Split(_emailBody, Char(10)), "Result", "_myGroupTable" )

    It is superior to Distinct in that it provides the distinct column as well as the rest of the columns in a table within the record:

    Capturef6.PNG

     

    Hope this helps. 

    Cheers!

  • Verified answer
    gerrysr6omfg Profile Picture
    37 on at

    Thanks, that helps a lot. But it returns a table, I got ChatGPT to show me how to convert the table to a String and got the final working code:

     

    Set(_emailBody, Concat(GroupBy(Split(_emailBody, Char(10)), "Result", "_myGroupTable"), Result, Char(10)));

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard