Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Calculation to default to 0 if its a negative number

(1) ShareShare
ReportReport
Posted on by

Hello,

 

I would appreciate some assistance, i am trying do an IF statement on Power apps where by i am doing a subtraction calculation on a textbox by minus 8 but if a number is negative it defaults to 0 so as not to bring some total calculations issues. I cannot seem to get the formula right.

 

the explanation should be "if overtime hours is less that 0 then overtime text box should be 0, otherwise subtract 8 hours from the paid hours text box" i hope this explanation helps

 

Thank you

  • TYNAI Profile Picture
    on at
    Re: Calculation to default to 0 if its a negative number

    Hi @Gochix 

    Thank you so much! This has worked! i think my explanation was not good in the beginning. This solution works perfectly

  • Verified answer
    Gochix Profile Picture
    1,933 Super User 2025 Season 1 on at
    Re: Calculation to default to 0 if its a negative number

    @TYNAI ,

    Sorry. If you say that you have txtPaidHours-8 as Default property for txtOTHours then change it to: 

    If(txtPaidHours-8 < 0,0,txtPaidHours-8)

     
    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • TYNAI Profile Picture
    on at
    Re: Calculation to default to 0 if its a negative number

    Hi @Gochix 

     

    The default of txtOTHours is already a hard coded 0, i have put the formula " txtPaidHours-8 " on the default calculation for txtOTHours it works well apart from giving the negative figures , based on this formula "txtPaidHours-8" is there an IF statement that will make all negative numbers to be 0 once "txtPaidHours-8" is run. I have tried putting the 

    If(Value(txtOTHours.Text) < 0,Reset(txtOTHours))

    on the on change part. but it still shows the negative figures 

  • Gochix Profile Picture
    1,933 Super User 2025 Season 1 on at
    Re: Calculation to default to 0 if its a negative number

    @TYNAI ,

     

    You can set the Default value for txtOTHours to 0.

    Then OnChange property set to :

    If(Value(txtOTHours.Text) < 0,Reset(txtOTHours))

     

    This might not be a solution if you already have a Default property set for txtOTHours..
    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

  • TYNAI Profile Picture
    on at
    Re: Calculation to default to 0 if its a negative number

    Hi @Gochix 

    For your questions.

     

    1) Looks like you have placed the formula in one of the text labels - txtOTHours? Yes this is correct

    2) a text input field or Text Label? Text Input field

    3)Where you want to display the final calculation? In other Text Label? The final calculation i.e setting negative number to be 0 should be in the txtOTHours

    4)Just to clarify this, where you getting the data of txtOTHours and txtPaidHours? The txtPaidHours is preset text input field of 8 hours, while the txtOTHours is gotten from a calculation of difference in time on the app

     

    "if overtime hours is less that 0 then overtime text box should be 0, otherwise subtract 8 hours from the paid hours text box"

    Basically i want the text input on the txtOTHours to only display positive numbers, since the app calculates overtime hours. Having a negative number will impact on the total number of hours

  • Gochix Profile Picture
    1,933 Super User 2025 Season 1 on at
    Re: Calculation to default to 0 if its a negative number

    Looks like you have placed the formula in one of the text labels - txtOTHours?

     

    Just to clarify this, where you getting the data of txtOTHours and txtPaidHours? -  a text input field or Text Label?

    Where you want to display the final calculation? In other Text Label?

     

    I can't understand the part of :

    "if overtime hours is less that 0 then overtime text box should be 0, otherwise subtract 8 hours from the paid hours text box"

     

  • TYNAI Profile Picture
    on at
    Re: Calculation to default to 0 if its a negative number

    Hello @Gochix 

     

    Thank you for the assist, seems there is something up with the formula, i have gotten this error when i applied the code. I am not sure what it meanspower2.PNG

  • Gochix Profile Picture
    1,933 Super User 2025 Season 1 on at
    Re: Calculation to default to 0 if its a negative number

    Hi @TYNAI ,

     

    If(Value(txtOTHours.Text) - Value(txtPaidHours.Text) < 0,txtPaidHours-8,0)

     

    Based on Text Labels.

    Adjust for yourself how you need this to deduct the hours. 
    _____________________________________________________________________________________
    Please give a thumbs up if I resolved your issue! Please click Accept as Solution to close the topic!

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