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 / How to remove the last...
Power Apps
Suggested Answer

How to remove the last part of a URL

(2) ShareShare
ReportReport
Posted on by 330
Still trying to wrap my head around using certain functions. I have a textbox where users are entering in the URL to their site. I want to be able to extract the part of the site that I need, especially if they past in a link to a document library. So for instance I am getting URLs like...
 
https://myDomain.SharePoint.com/sites/mySiteCollection/myDocLib/Forms/Allitems.aspx
https://myDomain.SharePoint.com/sites/mySiteCollection/mySubSite/docLibrary/Forms/Allitems.aspx
 
It should not matter if I am getting a top site collection or a subsite, I want to be able to just extract the site/subsite. Right now, I am doing something like this
Left(myTextBox.Text, Find("/Forms", myTextBox.Text)-1)
...and this is giving me outputs like...
 
https://myDomain.SharePoint.com/sites/mySiteCollection/myDocLib
https://myDomain.SharePoint.com/sites/mySiteCollection/mySubSite/docLibrary
 
this is getting me close to my desired output, but I still want to remove the text from the last "/". Without knowing the length of the name of the document library, how do I get my desired output which should be like...
 
https://myDomain.SharePoint.com/sites/mySiteCollection/
https://myDomain.SharePoint.com/sites/mySiteCollection/mySubSite/
 
 
Thanks in advance. 
Categories:
I have the same question (0)
  • Suggested answer
    Nandit Profile Picture
    1,568 Moderator on at
    Hi Spawn10,
     
    I have come up with a solution to this which works for the two examples you shared and should work for any link to a document library. Here is the formula: 
    If(
        //Checking if its a Doc Lib link
        !IsBlank(
            Find(
                "Forms",
                TextInputCanvas1.Value
            )
        ),
        //First removing everyting after /Forms in the link
        Left(
            Left(
                TextInputCanvas1.Value,
                Find(
                    "/Forms",
                    TextInputCanvas1.Value
                ) - 1
            ),
            //findind the last / char before the document library name and using it to get the all the text before it
            With(
                {
                    _link: Left(
                        TextInputCanvas1.Value,
                        Find(
                            "/Forms",
                            TextInputCanvas1.Value
                        ) - 1
                    ),
                    _lookingFor: "/"
                },
                If(
                    EndsWith(
                        _link,
                        _lookingFor
                    ),
                    Len(_link),
                    Find(
                        _lookingFor & Last(
                            Split(
                                _link,
                                _lookingFor
                            )
                        ).Value,
                        _link
                    )
                )
            )
        ),
        //Plain Link if its a direct link to a site or subsite
        TextInputCanvas1.Value
    )
     
    I hope this is helpful. 

    Kind regards,
    Nandit
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!
     
     
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at
    hey
     
    can u try this approach:
    Left(
        myTextBox.Text,
        Find(
            "|",
            Substitute(myTextBox.Text, "/", "|", Len(myTextBox.Text) - Len(Substitute(myTextBox.Text, "/", "")))
        )
    )
    
    if this helped please mark as verified answer so we can also help others.
     
    thanks
  • Meekou Profile Picture
    200 Moderator on at
    Due to the dynamic length of site and library name, we will not be able to use string extract the base site url.
     
    Are your provided site url are real exist?
     
    If so, you could try to get all the site urls by graph api and then compare it with your text string to find the most match site url.
     
    • PowerApps add Office365Groups connector
    • Add a button with code below:
    Set(SiteList, Office365Groups.HttpRequest("https://graph.microsoft.com/v1.0/sites?$select=webUrl&search=*","GET","").value);
    Set(Sites, SortByColumns(ForAll(SiteList,{WebUrl: Text(ThisRecord.webUrl),Length: Len(ThisRecord.webUrl)}),"Length",SortOrder.Descending));
    Set(MapSite, LookUp(Sites, !IsBlank(Find(WebUrl,myTextBox.Text))))
    • Run and check the result
     
  • timl Profile Picture
    37,248 Super User 2026 Season 1 on at
    Here's how you can adapt your original formula to remove the last part of the URL.
     
    As you say, you were close. The adaptation below splits your output by the / character and outputs all the elements, excluding the final chunk that corresponds to the last part of the URL.
     
    With(
        {splitUrl: Split(Left(myTextBox.Text, Find("/Forms", myTextBox.Text)-1), "/")},
        Concat(FirstN(splitUrl, CountRows(splitUrl)-1), Value, "/")
    )


     

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 337 Most Valuable Professional

#2
11manish Profile Picture

11manish 173

#3
Valantis Profile Picture

Valantis 86

Last 30 days Overall leaderboard