Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

How to remove the last part of a URL

(2) ShareShare
ReportReport
Posted on by 279
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:
  • timl Profile Picture
    34,939 Super User 2025 Season 1 on at
    How to remove the last part of a URL
    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, "/")
    )


     
  • Meekou Profile Picture
    189 Super User 2025 Season 1 on at
    How to remove the last part of a URL
    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
     
  • mmbr1606 Profile Picture
    12,108 Super User 2025 Season 1 on at
    How to remove the last part of a URL
    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
  • Suggested answer
    Nandit Profile Picture
    1,563 Super User 2025 Season 1 on at
    How to remove the last part of a URL
    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!
     
     

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard