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 / If statement for inven...
Power Apps
Answered

If statement for inventory calculations and update is not working

(0) ShareShare
ReportReport
Posted on by 534

Based on the value of a dropdown I set a variable named transTypeMode.  This works fine.

If(TransTyepDD.Selected.Value="CycleCount", Set(transTypeMode,"Update"), TransTyepDD.Selected.Value="Receipt", Set(transTypeMode,"Addition"),TransTyepDD.Selected.Value="Issue", Set(transTypeMode,"Subtraction"))

 

I have two text boxes and a label.  Based on the transTypeMode a calculation or update will occur.

Calculations.jpg

I tested each condition of the if statement separately and each one works.  When I combine all three statement into one it breaks.  For the life of me I cannot see the reason why.  I compared my syntax to the Microsoft If and Switch functions here and I still don't see the problem.

 

If (transTypeMode = "Update", TransQty, transTypeMode = "Addition", TransQty + QtyOnHand, transTypeMode = "Subtraction", QtyOnHand - TransQty)

 

Any suggestions?

 

Also...is there a better, more efficient way to build this feature?

 

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

    @tonykiefer 

    The space between If and ( maybe the issue? You could also try adding an else condition eg zero

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

    @tonykiefer 

     

    Set your Label Text property to the following formula:

    Switch(
     TransTyepDD.Selected.Value,
     "CycleCount", TransQty,
     "Receipt", TransQty + QtyOnHand
     "Issue", QtyOnHand - TransQty,
     "unkonwn"
    )
     

    The only unknowns in your formula are - what are TransQty and QtyOnHand?  Are these some sort of variables, some field, or a control?

     

    I hope this is helpful for you.

  • tonykiefer Profile Picture
    534 on at

    @RandyHayes...Thanks for the reply.  TransQty and QtyOnHand are the names of the text boxes under TranQuantity and Quantity on Hand respectively.  

     

    The Test Qty Label and text box are used for testing the If/Switch statement to make sure the calculations are working before I apply the changes to the db.

     

    Initially, when the TransType was selected I was setting a variable as described above in my initial post.  From you switch statement I gather it's not necessary to set the variable because I can just use the TransTypeDD.Selected.Value.  This is a cleaner approach.

     

    The outcome should be.

    IF the TransTypeDD.Selected.Value = Update THEN I'll replace the current db value.

    IF the TransTypeDD.Selected.Value = Receipt THEN add the TransQty and QtyOnHand.

    IF the TransTypeDD.Selected.Value = Issue THEN subtract TransQty from QtyOnHand.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @tonykiefer 

    Yes - avoid variables as much as you can.  You usually don't need them except for what they were designed for.

    If those TransQty and QtyOnHand are text boxes, then you need to reference them as such and the proper property that contains the value you want (.Text).

     

    Change your formula to the following if that is the case:

    Switch(
     TransTyepDD.Selected.Value,
     "CycleCount", TransQty.Text,
     "Receipt", Text(Value(TransQty.Text) + Value(QtyOnHand.Text))
     "Issue", Text(Value(QtyOnHand.Text) - Value(TransQty.Text)),
     "unkonwn"
    )
  • tonykiefer Profile Picture
    534 on at

    @RandyHayes...Thank you very much for the insight!  It seems I'm still stuck in .Net development mode and I have to simplify my approach.  Overthinking is a killer when it comes to development.

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

    @tonykiefer 

    Yes, PowerApps is not development.  It is just like Excel in that you create formulas that reference "cells" just like you do in Excel.

    Kicking the developer habit is the hardest thing to do (took me a bit of time coming from .Net dev as well).  BUT, once you do, it is smooth sailing from there and you will then spend much more time designing cool things and functionality into your app as opposed to trying to "figure out" how to do something. 

    Keep it super simple!!

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 542 Most Valuable Professional

#2
Haque Profile Picture

Haque 206

#3
Kalathiya Profile Picture

Kalathiya 201 Super User 2026 Season 1

Last 30 days Overall leaderboard