Skip to main content

Notifications

Community site session details

Community site session details

Session Id : MVszTeJF2K/8m8sLQnWAb2
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 Super User 2025 Season 1 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 Super User 2025 Season 1 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 Super User 2025 Season 1 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,017 Most Valuable Professional

Leaderboard
Loading started
Loading complete