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 / divide by zero error i...
Power Apps
Answered

divide by zero error in monitor although handled in code

(2) ShareShare
ReportReport
Posted on by 711
Hi,
 
 
Why does monitor throw a divide by zero error on
 
                 If(
                     ThisItem.pl_NumVar01=0 Or IsBlank(ThisItem.pl_NumVar01)
                     ,1
                     ,ThisItem.pl_NumVar01>0
                     ,ThisItem.pl_NumVar01
                     ,ThisItem.pl_NumVar01<0
                     ,Abs(1/ThisItem.pl_NumVar01)
                     ,0
                    )
 
altough handled and how prevent elegantly
 
also:
I was going to ask this question but after composing a text an pressing send I forget to choose a category. The result is a new blank form and not any way to get back tot my question.
What am I doing wrong? The forum cannot be this harsh or amateuristic by design. Is there a forum feedback opportunity
 
Categories:
I have the same question (0)
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @HansHeintz,
     
    Could you please try below approach and check?
    With(
        { _val: ThisItem.pl_NumVar01 },
        If(
            IsBlank(_val) Or _val = 0, 
                1,
            _val > 0,               
                _val,
            Abs(1 / If(_val = 0, 1, _val)) 
        )
    )
    ---------------------------------------------------------------------------
    Glad it helped 🙂
    If this fixed your issue,
    please click “Does this answer your question?” to mark it as verified so others can find the solution easily.
    A Like 👍 is always appreciated, and I’m around if you need more help @Kalathiya
  • Suggested answer
    Haque Profile Picture
    3,653 on at
     
     
    The If function in Power Apps expects pairs of conditions and results, but your formula has an extra condition without a matching result, causing unexpected evaluation order.
     
    Please try this:
    If(
        IsBlank(ThisItem.pl_NumVar01) || ThisItem.pl_NumVar01 = 0,
        1,
        ThisItem.pl_NumVar01 > 0,
        ThisItem.pl_NumVar01,
        ThisItem.pl_NumVar01 < 0,
        Abs(1 / ThisItem.pl_NumVar01),
        0
    )
    
     
    or better nested if
     
    If(
        IsBlank(ThisItem.pl_NumVar01) || ThisItem.pl_NumVar01 = 0,
        1,
        If(
            ThisItem.pl_NumVar01 > 0,
            ThisItem.pl_NumVar01,
            If(
                ThisItem.pl_NumVar01 < 0,
                Abs(1 / ThisItem.pl_NumVar01),
                0
            )
        )
    )
    
     
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    my view is that :
    • The divide-by-zero warning is likely caused by Monitor evaluating the division expression during analysis, even though your logic protects against it.
    • Refactoring the formula using With(), nested If(), or IfError() can reduce or eliminate the warning.
  • Verified answer
    Valantis Profile Picture
    6,735 on at
     
    The issue is that Power Apps Monitor evaluates all branches of an If expression eagerly during analysis, not lazily. So even though your zero check fires first at runtime, the Monitor sees the division expression and flags it regardless.
    The cleanest fix is IfError wrapping the division:
    If(
        IsBlank(ThisItem.pl_NumVar01) || ThisItem.pl_NumVar01 = 0,
        1,
        ThisItem.pl_NumVar01 > 0,
        ThisItem.pl_NumVar01,
        IfError(Abs(1 / ThisItem.pl_NumVar01), 0)
    )
    IfError catches the division at runtime if zero somehow slips through, and it also satisfies Monitor's static analysis because the error handling is explicit. This is the most defensive pattern and eliminates the warning.
     

     

    Best regards,

    Valantis

     

    ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/

    💼 LinkedIn

    ▶️ YouTube

  • Suggested answer
    Ram Prakash Duraisamy Profile Picture
    5,877 Super User 2026 Season 1 on at
     
    The divide-by-zero error is triggered by Abs(1 / ThisItem.pl_NumVar01). Although your If() statement checks for zero first, Power Fx Monitor may still evaluate or analyze all branches and detect the potential error. To avoid this, guard the division directly with an additional zero check or use IfError() to handle the exception gracefully.
     
    Please mark as answer if my suggestion helps.
    Subscribe here for More Useful videos : https://www.youtube.com/@rampprakash3991

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard