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 / Compare two numbers us...
Power Apps
Answered

Compare two numbers using a IF statement

(0) ShareShare
ReportReport
Posted on by 56

 

I have a simple form and what to compare 2 values 

 

If(TotalComp>TotalMonths,"Yes","No")

 

This is what I think the value should be but it does not work

 

When the user enters a DOB this calculates the age into months as a label This is TotalMonths

 

If (DateDiff (Today (), Date (Year (Now ()), Month (DataCardValue1.SelectedDate), Day (DataCardValue1.SelectedDate))) <= 0, DateDiff (DataCardValue1.SelectedDate, Today (),TimeUnit.Months),DateDiff (DataCardValue1.SelectedDate, Today (),TimeUnit.Months) - 1)

 

I then have a 2nd label which is the calculation of their comprehension age This is TotalComp

Sum(DataCardValue7*12 + DataCardValue8) 

 

 

 

BCWdesign_0-1692774748044.png

 

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @BCWdesign,

     

    If the combobox is a choice field please try (DefaultSelectedItems property):

     

    If(
     Value(TotalComp.Text) > Value(TotalMonths.Text),
     {Value: "Yes"},
     {Value: "No"}
    )

     

    When comparing control values, always extend the control name with the property you would like to reference (e.g. .Text). Additionally, when comparing numbers within a label or text input use the Value() function.

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • BCWdesign Profile Picture
    56 on at

    BCWdesign_0-1692776791611.png

    Thanks still having issues with the type here is what happens

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    @BCWdesign if you want to visualize it in a label or textinput, we will need to make a slight adjustment:

     

    If(
     Value(TotalComp.Text) > Value(TotalMonths.Text),
     "Yes",
     "No"
    )

     

    Could you give this a try? 😊

  • Verified answer
    BCWdesign Profile Picture
    56 on at

    That works perfectly : )

    How would I adapt it for a dropdown box? or as part of a form?

     

    If(
     Value(TotalComp.Text) > Value(TotalMonths.Text),
     {Value: "Yes"},
     {Value: "No"}
    )

     

    BCWdesign_0-1692782020932.png

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    @BCWdesign,

     

    To auto-fill a choice column in a Form you will need to write the code in the DefaultSelectedItems property. In case the error occurs there as well, would it be possible to provide some additional info:

     

    • What is the exact error when hovering over the red lining?
    • What is the Items property of the combobox?

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
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 627

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard