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

Community site session details

Session Id : joU7eFufzXoYqGTYAnlusK
Power Apps - Power Apps Experimental Features
Suggested answer

Formula for calculating weighted cost inconsistent results

Like (1) ShareShare
ReportReport
Posted on 21 Mar 2025 13:25:41 by 378
Hello! I'm hoping someone can advice what im doing wrong or if there could be a better way of achieving the outcome im after.
 
Essentially I have a submit button that calculates a new weighted unit cost.
 
For example, I have 25 items in stock with a unit cost of 2.  I want to restock the item by 75 however the new unit cost is 5, therefore my calculating needs to work out a weighted unit cost for the item. In this scenario, the unit cost should be 4.25. 
 
Total cost / total quantity
425 / 100 = 4.25
 
I have just tested this twice, the first time it worked, the second time it calculated it at 0.5. 
 
So, how i've currently setup the process. OnVisible for the screen I set the current quantity and the current cost.
 
Then on the submit button, I have this calculation, which I then use to patch the selected item with the new values. The sum for stock works, just not the new unit cost. 
 
 
 
I'm hoping there is just a more simple way to achieve this, as I really can't understand how it sometimes works and sometimes doesnt.
 
Thanks all
 
I have the same question (0)
  • Suggested answer
    Jap11 Profile Picture
    378 on 21 Mar 2025 at 16:29:39
    Formula for calculating weighted cost inconsistent results
    I resolved the issue, it was treating the second number as 0 because i was not clicking off the text box before selecting submit.
     
    Tested this theory and each time i submit without clicking off the text box, it fails to calculate correctly but when i do click off, it works. 
     
    Explains why it was inconsistent.
     
    I will add a confirm button before allowing the submit button to become visible.
     
  • Michael E. Gernaey Profile Picture
    51,803 Super User 2025 Season 2 on 21 Mar 2025 at 20:18:47
    Formula for calculating weighted cost inconsistent results
    Hi @Jap11
     
    Just curious. Is that a class InputText in Number mode, or a Modern NumberInput ?
     
     
  • Jap11 Profile Picture
    378 on 22 Mar 2025 at 08:52:56
    Formula for calculating weighted cost inconsistent results
    Hello @Michael E. Gernaey - yes it's a modern NumberInput

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 686 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 433 Super User 2025 Season 2

#3
wolenberg_ Profile Picture

wolenberg_ 266 Moderator

Last 30 days Overall leaderboard

Featured topics

Loading complete