web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Display negative numbe...
Power Apps
Answered

Display negative number as zero

(0) ShareShare
ReportReport
Posted on by 22

Hi.

 

I have a gallery used in an order form app where it displays the quantity in stock of each item. 

People are allowed to order items that are out of stock so I would like the item to display 0 of no items are in stock but what happens when people order is the available qty then displays a negative number which has confused people. 

 

Is there a way in my code I can say if the number is less than 0 display 0? 

This is the code I currently have

 

"Available in Stock: " & LookUp('PPE Stock',Title=ThisItem.Title,Qty)

 

 As shown it currently displays the live stock figure but the second item shows -4 which is where the confusion comes in for people. 

cdowkes_0-1665416240230.png

Thank you.

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    Hello,

     

    Sure, try the following:

    "Available in Stock: " & If(LookUp('PPE Stock',Title=ThisItem.Title,Qty)<0,0,LookUp('PPE Stock',Title=ThisItem.Title,Qty))

     

    this is a simple "If", the condition is using the result of your lookup to make sure the value displayed is always >= 0

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @cdowkes 

    Please consider changing your Formula to the following:

    "Available in Stock: " & 
     With(LookUp('PPE Stock',Title=ThisItem.Title),
     If(Qty<0, 0, Qty)
     )

     

    I hope this is helpful for you.

  • cdowkes Profile Picture
    22 on at

    Hi. 

    Thank you for your quick response. I tried the code as you suggested however I'm getting an error message. Again this could be me misunderstanding I'm still trying to learn as I go. 

    cdowkes_0-1665489660690.png

     

  • cdowkes Profile Picture
    22 on at

    Hi. 

     

    Thanks for the quick reply. I used the code as you suggested however I'm now getting an error message. Could this be something to do with how I've set up the data?

    cdowkes_1-1665489806776.png

     

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    Hello,

    The error is saying that the data type is not the expected one, that column "Qty" is a string and needs to be converted to a number, to do this, please use the Value function Value function in Power Apps - Power Platform | Microsoft Learn 

     

    try the following, using the idea of @RandyHayes 

    "Available in Stock: " & 
     With(LookUp('PPE Stock',Title=ThisItem.Title),
     If(Value(Qty)<0, 0, Value(Qty))
     )

     

  • cdowkes Profile Picture
    22 on at

    Perfect. 

     

    Thank you

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard