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 / i don't know how to ap...
Power Apps
Unanswered

i don't know how to apply Switch statement to bmi calculator

(0) ShareShare
ReportReport
Posted on by 14

Hello, I recently started with power apps and one of the very first app I am building is a Body mass index(BMI) calculator. I was able to set it to automatically convert from Kg to pounds and cm to feet. The problem I am facing now is outputting the result using IF or Switch statement to show the BMI categories

BMI Categories:
Underweight = <18.5
Normal weight = 18.5–24.9
Overweight = 25–29.9
Obesity = BMI of 30 or greater

 

The formula I intend to use is

BMI = 703* (weight/(Height^2))

 

This is the logic I used

Set(VarResult,If(tx1.Text/(tx2.Text^2)*703)=<18.5,"underweight")
if(VarResult>18.5,"Normal")
if(VarResult>=24.5,"Overweight")
if(VarResult>30, "Obese")).

 

Please help

 

 

Categories:
I have the same question (0)
  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @ojobabs 

    The Switch function looks for an exact match, therefore, a simple way to do this would be to use if statements.

    With this example, you could set the text property of a label to the following formula to show the BMI result.

    With({res:Value(tx1.Text)/(Value(tx2.Text)^2)*703},
     If(res<=18.5, "Underweight",
     res<=24.5, "Normal",
     res<=30, "Overweight",
     "Obese"
     )
    )
    
    

     

     

  • ojobabs Profile Picture
    14 on at

    You fully broke down the select statement, but your answer does not solve my problem. After running your code, I keep getting "underweight" for correct values. Furthermore, I am working on improving my calculations. Thanks for assisting.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Your With statement is incorrect. Also there is no need for Value() arithmetic operators automatically convert text to numbers in PowerApps.

    _1.png

     

    With({res:(tx1.Text) / (tx2.Text) ^ 2 * 703},
     If(res <=18.5, "Underweight",
     res <=24.5, "Normal",
     res <=30, "Overweight",
     "Obese"
     )
    )

     

     

     

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    @ojobabs 

    The only thing that might be wrong here is the placing of the parenthesis.

    With({res:(tx1.Text / (tx2.Text) ^ 2) * 703},
     If(res <=18.5, "Underweight",
     res <=24.5, "Normal",
     res <=30, "Overweight",
     "Obese"
     )
    )

    Whilst, @Drrickryp is correct in that PowerApps will implicitly convert text to numbers, I used Value to explicitly carry out the conversion to avoid any ambiguity.

     

    If that still doesn't work, I would set the text property of a label to the following formula to investigate whether the underlying calculation produces the expected value:

    (tx1.Text / (tx2.Text) ^ 2) * 703

  • Verified answer
    ojobabs Profile Picture
    14 on at

    Thank you all for your help, the calculation error is from my end.
    Below is the correct equation
    With(
    {res:Value(tx1.Text)/(Value(tx2.Text)^2)*10000},
    If(
    res>= 30, "Obese",
    res> 25 && res< 29.9, "Overweight",
    res> 18.5 && res< 24.9, "Normal",
    res<= 18.4, "Underweight"
    )
    )

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard