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 / Calculation to default...
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

power.PNG
Categories:
I have the same question (1)
  • Gochix Profile Picture
    1,937 Moderator on at

    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!

  • TYNAI Profile Picture
    on at

    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,937 Moderator on at

    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

    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,937 Moderator on at

    @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

    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 

  • Verified answer
    Gochix Profile Picture
    1,937 Moderator on at

    @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

    Hi @Gochix 

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard