Skip to main content
Community site session details

Community site session details

Session Id : J+dahGKM2H3GocfSLK9xAO
Power Apps - Building Power Apps
Answered

Compare two numbers using a IF statement

Like (0) ShareShare
ReportReport
Posted on 23 Aug 2023 07:19:31 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:
  • LaurensM Profile Picture
    12,510 Moderator on 23 Aug 2023 at 10:16:47
    Re: Compare two numbers using a IF statement

    @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?
  • Verified answer
    BCWdesign Profile Picture
    56 on 23 Aug 2023 at 09:15:48
    Re: Compare two numbers using a IF statement

    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

     

  • Verified answer
    LaurensM Profile Picture
    12,510 Moderator on 23 Aug 2023 at 07:53:38
    Re: Compare two numbers using a IF statement

    @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? 😊

  • BCWdesign Profile Picture
    56 on 23 Aug 2023 at 07:47:14
    Re: Compare two numbers using a IF statement

    BCWdesign_0-1692776791611.png

    Thanks still having issues with the type here is what happens

  • LaurensM Profile Picture
    12,510 Moderator on 23 Aug 2023 at 07:34:16
    Re: Compare two numbers using a IF statement

    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!

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete