Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Error Handling
Answered

The second argument to the 'Replace' function must be greater than or equal to 1

(0) ShareShare
ReportReport
Posted on by 7

Hi all, when enabling Formula-level error management I'm getting the error "The second argument to the 'Replace' function must be greater than or equal to 1"

 

The below formula is what it is referring to which appears to be working as expected. I didn't create the app originally but am maintaining it and I wanted to enable the error management to handle NULL values. Any ideas?

 

Concatenate(

    "Something went wrong with a previous attempt to save the report. Click below to go back to the report and check the following sections for completeness: ",

    Replace(lclMissingListItemNames,Len(lclMissingListItemNames)-1,Len(lclMissingListItemNames),".")

)

 

 

TIA

 

Paul

  • Paul_Owen Profile Picture
    7 on at
    Re: The second argument to the 'Replace' function must be greater than or equal to 1

    Thanks Carlos solution helps tremendously and works perfectly.

  • Verified answer
    CarlosFigueira Profile Picture
    on at
    Re: The second argument to the 'Replace' function must be greater than or equal to 1

    As the error message suggests, the second parameter to the Replace function must be at least 1, so if the length of the lclMissingListItemNames variable is less than 2 (or it is blank, in which case it would have a length of 0), then you will see this error. With 'Formula-level error management' disabled you would get a blank value instead of the error. There are a few ways you can solve this:

    • "Capture" the error with the IfError function, and replace it with something else (such as Blank(), which was the previous result):
      • IfError(Replace(lclMissingListItemNames,Len(lclMissingListItemNames)-1,Len(lclMissingListItemNames),"."), Blank())
    • Check if the variable is large enough to do the replacement:
      • If(Len(lclMissingListItemNames) > 1, Replace(lclMissingListItemNames, Len(lclMissingListItemNames)-1, Len(lclMissingListItemNames),"."), Blank())

    Notice that you can simplify those expressions with the With function so that you won't need to repeat the same expression multiple times:

    • IfError(With({ l: Len(lclMissingListItemNames) }, Replace(lclMissingListItemNames, l - 1, l, "."), Blank()))
    • With({ l: Len(lclMissingListItemNames) }, If(l > 1, Replace(lclMissingListItemNames, l - 1, l, "."), Blank()))

    Hope this helps!

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 Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Error Handling

#1
stampcoin Profile Picture

stampcoin 73

#2
DS-11051211-0 Profile Picture

DS-11051211-0 20

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 9

Overall leaderboard

Featured topics