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 / How to make a field va...
Power Apps
Answered

How to make a field validate with a higher value than another field

(0) ShareShare
ReportReport
Posted on by 91

Hi All,

 

I have four fields in a form-

Start Odo and End Odo

Start Date/Time and End Date/Time

 

I would like to make it so that the End Odo field must validate to be higher value than the Start Odo field when a user enters data and the same with Start and End Date/Time.

 

If it is lower, the form throws up an error when submit is pressed and likewise with date/time fields. However, I need to have it so that if there is nothing entered in the End Odo field the form will still submit. (so the user creates a record and come back to it later to complete it) It should only throw an error if a user actually enters a number in it.

 

I have tried something like this code in the End Odo 'OnChange' field which does throw up an error saying that its lower, but I'm not sure about what to put in the 'Submit' button-

 

If(Value(DataCardValue35.Text)>Value(DataCardValue48.Text),Notify("End Odometer must be more than Start Odometer",Error);Reset(Self))

 

Appreciate any help.

1.JPG
Categories:
I have the same question (0)
  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @GordoPwrApp,
    Do you want to throw an error only when the end date is lower than the start date?

     

    I suggest you set the DisplayMode property of the submit button as below:

    If(Value(DataCardValue35.Text)>Value(DataCardValue48.Text),Disabled,Edit)

    Then set the OnSelect property of the submit button as below:

    SubmitForm(Form1)

     

  • GordoPwrApp Profile Picture
    91 on at

    Hi @v-qiaqi-msft 

     

    Thanks for your reply.

     

    I can't have the submit button greyed out, as I still need the option for a user to submit and create a record without an end odometer, so they have the option to complete that later at the end of their trip.

     

    I only want an erro pop up when the user actually enters a value in the end odo field, and trigger if it is lower than the start odo field.

     

    In regards to the start and end date, I have it working ok with the below code-

     

    If(
    Or(
    IsBlank(
    DateValue3.SelectedDate + Time(
    Value(HourValue3.Selected.Value),
    Value(MinuteValue3.Selected.Value),
    0
    )
    ),
    IsBlank(
    DateValue2.SelectedDate + Time(
    Value(HourValue2.Selected.Value),
    Value(MinuteValue2.Selected.Value),
    0
    )
    )
    ),
    Set(
    IsEndDateValid,
    true
    ),
    DateDiff(
    DateValue2.SelectedDate + Time(
    Value(HourValue2.Selected.Value),
    Value(MinuteValue2.Selected.Value),
    0
    ),
    DateValue3.SelectedDate + Time(
    Value(HourValue3.Selected.Value),
    Value(MinuteValue3.Selected.Value),
    0
    ),
    Minutes
    ) > 0,
    Set(
    IsEndDateValid,
    true
    ),
    Set(
    IsEndDateValid,
    false
    )
    )

     

     

    And on the submit button-

     

    If(IsEndDateValid,SubmitForm(Form1))

     

  • GordoPwrApp Profile Picture
    91 on at

    Hi @v-qiaqi-msft ,

     

    I have changed the display mode of the submit button and it is working with a variable i created - viewmode1, however is there a way to also have the submit button enabled if the field is blank?

     

    Something like-

    If(Value(DataCardValue17_3.Text)>Value(DataCardValue26_3.Text),Set(viewmode1,true)); If(Value(DataCardValue17_3.Text)<Value(DataCardValue26_3.Text),Set(viewmode1,false)); If(IsBlank(DisplayMode.Edit)

     

    Thanks

  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @GordoPwrApp,

    Which field is blank? Both of DataCardValue17_3 and DataCardValue26_3?

  • GordoPwrApp Profile Picture
    91 on at

    @v-qiaqi-msft just DataCardValue26_3 - which is the end odometer.

     

    So a user should be able to create a record with a blank end odometer or if they do enter a value in the end odometer, it must be higher than DataCardValue17_3 (start odometer), otherwise they can't submit

     

    Thanks

  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @GordoPwrApp,

    So if the DataCardValue26_3 is blank or DataCardValue26_3 is higher than DataCardValue17_3, the submit button should be enable, right?

     

    Modify your formula as below:

    If(Value(DataCardValue17_3.Text)>Value(DataCardValue26_3.Text),
     Set(viewmode1,true), 
     Value(DataCardValue17_3.Text<Value(DataCardValue26_3.Text)||IsBlank(DataCardValue26_3.Text),
     Set(viewmode1,false)
    )

    Or you could directly set the DisplayMode of the submit button as below:

    If(Value(DataCardValue17_3.Text)>Value(DataCardValue26_3.Text),
     Disabled, 
     Value(DataCardValue17_3.Text<Value(DataCardValue26_3.Text)||IsBlank(DataCardValue26_3.Text),
     Edit
    )​
  • GordoPwrApp Profile Picture
    91 on at

    @v-qiaqi-msft Yep thats correct. I've changed the DisplayMode of the submit button, however its still not enabling when the field is blank.

     

    DisplayMode of Submit Button-

    If(Value(DataCardValue17_3.Text)>Value(DataCardValue26_3.Text),Disabled,Value(DataCardValue17_3.Text)<Value(DataCardValue26_3.Text)||IsBlank(DataCardValue26_3.Text),DisplayMode.Edit)

    Vid1.gif

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @GordoPwrApp,

    Modify as below:

    If(
     Value(DataCardValue17_3.Text) > Value(DataCardValue26_3.Text) &&!IsBlank(DataCardValue26_3.Text),
     Disabled,
     Value(DataCardValue17_3.Text) < Value(DataCardValue26_3.Text) ,
     DisplayMode.Edit
    )

    vqiaqimsft_0-1668657967254.png

     

  • GordoPwrApp Profile Picture
    91 on at

    @v-qiaqi-msft worked perfectly, Thanks for your help!

  • GordoPwrApp Profile Picture
    91 on at

    @v-qiaqi-msft one more for you if you can please-

     

    How would i set a global variable so that I can display an Icon on another screen when a certain field is empty in a gallery. Then when the field gets completed, the icon disappears.

     

    Eg. a user creates a record and fills out the Start Odometer but not the End Odometer. On the home screen of the app, the user is reminded they have an incomplete entry as a icon is displayed.

     

    I have managed to get an icon visible by using 'If(IsBlank(Label21_1), true, false)' in the visible properties of the icon and where Label21_1 is the end odo field in my gallery, however the icon does not show straight away, until I hard close and re-open the app, and still then its a bit hit and miss.

    1.JPG

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 494

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
11manish Profile Picture

11manish 323

Last 30 days Overall leaderboard