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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Where do I put TrimEnd...
Power Apps
Suggested Answer

Where do I put TrimEnds for this collection

(1) ShareShare
ReportReport
Posted on by 691
Hey folks,
 
So I have a drop down menu that just displays a collection.  This collection is a list of branches it's pulling from SQL.  The problem is on occasion someone will copy/paste a branch and it'll have a space in the beginning or end, and since I'm tired of telling them I just want to fix it, but I can't figure out where to put the TrimEnds().  Where is what my collection declaration looks like : 
 
 
I've tried it around the whole Collect line, around Branchoffice, around Result...and more but I can't seem to get it right? Any help is appreciated.
I have the same question (0)
  • Suggested answer
    Pstork1 Profile Picture
    68,898 Most Valuable Professional on at
    Does thisrecord.value represent a single text field or something else?  If its text then you should be able to do the trimends() around the result field you are generating from the distinct.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
     
  • Suggested answer
    VASANTH KUMAR BALMADI Profile Picture
    176 on at

    You’re very close — the issue is just where TrimEnds() is allowed to be used.

    TrimEnds() works on text values, not on tables or entire collections.
    So you can’t wrap it around Collect() or around the SQL result itself — it must be applied at the column level while you’re building the collection.

    ✅ Correct way to fix it

    You need to trim the column inside the collection creation, using AddColumns or RenameColumns.

    ✅ Example

    If your SQL result column is called BranchOffice, do this:

    ClearCollect(
        colBranches,
        AddColumns(
            SQLBranches,
            "BranchOffice_Clean",
            TrimEnds(BranchOffice)
        )
    );
    

    Then set your dropdown to use:

    • ValueBranchOffice_Clean

    ✅ If you want to overwrite the original column name

    You can do it like this:

    ClearCollect(
        colBranches,
        RenameColumns(
            AddColumns(
                SQLBranches,
                "BranchOffice",
                TrimEnds(BranchOffice)
            ),
            "BranchOffice",
            "BranchOffice"
        )
    );
    

    But normally the first approach is cleaner.

    ✅ Most common and simplest version

    ClearCollect(
        colBranches,
        AddColumns(
            YourSQLCollection,
            "BranchOffice",
            TrimEnds(BranchOffice)
        )
    );
    

    Power Apps evaluates TrimEnds() row by row, which is exactly what you want.

    ❌ Why your attempts didn’t work

    These don’t work because:

    TrimEnds(Collect(...))   // ❌ TrimEnds expects text, not a table
    
    TrimEnds(Result)         // ❌ Result is a record/table
    
    TrimEnds(SQLBranches)    // ❌ table, not text
    

    Power Fx functions are strongly typed — trimming must be applied to a text column, not to the dataset.

    ✅ Final dropdown setup

    Dropdown.Items = colBranches
    Dropdown.Value = "BranchOffice"
    

    Now whether users enter:

    "New York"
    " New York"
    "New York "
    "   New York   "
    

    they will all display identically.

    ✅ Bonus tip (recommended)

    If duplicates are possible due to spaces, you can also normalize it:

    ClearCollect(
        colBranches,
        Distinct(
            AddColumns(
                SQLBranches,
                "BranchOfficeClean",
                TrimEnds(BranchOffice)
            ),
            BranchOfficeClean
        )
    );
    

    This removes duplicates caused only by leading/trailing spaces.

    ✔ Bottom line

    • TrimEnds() must be applied inside AddColumns

    • It works per record, not on collections

    • This permanently cleans the dropdown display

    Once you do this, you’ll never have to worry about leading or trailing spaces again 👍

  • WarrenBelz Profile Picture
    153,698 Most Valuable Professional on at
    Please be mindful of the Responsible AI policies for the Community guidelines. This also applies to this post.
     
    While we all appreciate responses to community posts, the enquirer needs to know the source of the answer. Also other responders may want to provide a more focussed and considered response as an option. 
     
    There is an Assisted by AI option where you can flag this so the material can be considered with appropriate weight.
  • CharlesBrewer Profile Picture
    691 on at
    @Pstork1 Sorry for the late reply, but it didn't email me to let me know someone replied :/
    So I'm not sure how you mean, but I've tried : 
     
    {Result: TrimEnds(ThisRecord.Value)}),Result));
    {Result: ThisRecord.Value}),TrimEnds(Result)));
     
    Any other variation instantly gets the red lines of "no".
     
    And I had no idea what to do with @VASANTH KUMAR BALMADI response since that seems more like a rewrite of some sort :(
  • Suggested answer
    WarrenBelz Profile Picture
    153,698 Most Valuable Professional on at
    Yes - the post from @VASANTH KUMAR BALMADI seems to be a straight copy and paste ChatGPT response (which is why I noted the forum code that applies). I suggest a couple of things- firstly you do not need the Result complexity - this was only a workaround when the output of Distinct was changed from Result to Value a few years back. You can also do this in one collection and have a field Value as well as trimming your Branchoffice field as below
    ClearCollect(
       collectAll,
       {Value: "All Branches"},
       Sort(
          Distinct(
             AddColumns(
                'View.PowerApps.ServiceLaptops',
                Trimmed,
                TrimEnds(Branchoffice)
             ),
             Trimmed
          ),
          Value
       )
    );
    Be aware that Distinct is a "local" client-side operation, so you will only be able to address record numbers in thta view up to your Data Row Limit.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 468

#2
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 332 Super User 2025 Season 2

Last 30 days Overall leaderboard