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 Apps
Answered

Help Please

(1) ShareShare
ReportReport
Posted on by 394 Super User 2024 Season 1

Dear All,

 

I have the following formula which clears input if a date picker selects:

 

Earlier than today

More than month

Weekend

After 9:10 same day

 

I also want to include a error if someone does this like a notification after its cleared. Can anyone help with this?

 

Kind Regards

 

Daniel

 

If(

Self.SelectedDate < Today() ||

DateTimeValue(Now()) > DateTimeValue(Text(Self.SelectedDate & " " & Time(9, 10, 0), "MM/DD/YYYY hh:mm AM/PM")) ||

DateDiff(Today(), Self.SelectedDate) > 31 ||

Weekday(Self.SelectedDate, StartOfWeek.Monday) = 6 || // Saturday

Weekday(Self.SelectedDate, StartOfWeek.Monday) = 7, // Sunday

Reset(Self)

)

Categories:
  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    Hi @DLCaterhamSch,

     

    Sure, you can provide a notification to the user by calling the Notify function:

    https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-showerror


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    So I have worked out a bit but cannot do two items together, count rows part and if start date is greater than end date.

     

    If(
    DataCardValue5_2.SelectedDate > DataCardValue13_2.SelectedDate,
    Notify("Start Date is greater than End Date"),
    SubmitForm(formEditRequestScreen_2)

    CountRows(
    Filter(
    [
    DataCardValue19.Value,
    DataCardValue20.Value,
    DataCardValue21.Value
    ],
    Value = true
    )
    ) > 1,
    Notify(
    "You can only make one selection.",
    NotificationType.Error
    ),
    SubmitForm(formEditRequestScreen_2)
    )

  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    Use the semicolon (:) at the end of each line to perform multiple actions before moving to the next part of the If function, like this:

    If(
     DataCardValue5_2.SelectedDate > DataCardValue13_2.SelectedDate,
     Notify("Start Date is greater than End Date");
     SubmitForm(formEditRequestScreen_2);
     ...

    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    Thank you for this and getting there. I still have issue that it still submits even though the start date is greater than end date:

     

    If(
    DataCardValue5_2.SelectedDate > DataCardValue13_2.SelectedDate,
    Notify(
    "Start date is greater than end date.",
    NotificationType.Error
    ),
    SubmitForm(formEditRequestScreen_2)
    );

  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    My pleasure. The code there looks good so if you see the notification message, I would not expect that instance of the SubmitForm function to be called.

     

    Is the SubmitForm function called elsewhere? For example, after the If function?


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    Its called in another if function as below. Maybe because I am calling it twice?

     

    // Validation if start date is greater than end date error
    If(
    DataCardValue5_2.SelectedDate > DataCardValue13_2.SelectedDate,
    Notify(
    "Start date is greater than end date.",
    NotificationType.Error
    ),
    SubmitForm(form)
    );


    // Validation if all selection options selected error
    If(
    CountRows(
    Filter(
    [
    DataCardValue19.Value,
    DataCardValue20.Value,
    DataCardValue21.Value
    ],
    Value = true
    )
    ) > 1,
    Notify(
    "You can only make one selection.",
    NotificationType.Error
    ),
    SubmitForm(form)
    );

     

  • KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    Yes, well spotted, it's the 2nd If block which us allowing the SubmitForm function to be called.

     

    Try the following code which handles all errors before allowing the SubmitForm function to be called:

    // Validation if start date is greater than end date error
    If(
     DataCardValue5_2.SelectedDate > DataCardValue13_2.SelectedDate,
     Notify(
     "Start date is greater than end date.",
     NotificationType.Error
     ),
    
     // Validation if all selection options selected error
     CountRows(
     Filter(
     [
     DataCardValue19.Value,
     DataCardValue20.Value,
     DataCardValue21.Value
     ],
     Value = true
     )
     ) > 1,
     Notify(
     "You can only make one selection.",
     NotificationType.Error
     ),
     SubmitForm(form)
    );

    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

  • DLCaterhamSch Profile Picture
    394 Super User 2024 Season 1 on at

    I only spotted because you directed me to it, so thank you! How stop someone selected all toggles to false as well? I tried changing true to false in this code and added it to code above but doesn't have the same effect i think? Basically i only want one toggle allowed and not allow none to be selected if that makes sense?

     

    // Validation if all catering options selected error
    If(
    CountRows(
    Filter(
    [
    DataCardValue19.Value,
    DataCardValue20.Value,
    DataCardValue21.Value
    ],
    Value = false
    )
    ) > 1,
    Notify(
    "You need to select an option.",
    NotificationType.Error
    ),

  • Verified answer
    KeithAtherton Profile Picture
    3,709 Most Valuable Professional on at

    My pleasure! Try changing the code as follows, i.e. count of checkboxes set to true = 1:

    // Validation if all catering options selected error
    If(
    CountRows(
    Filter(
    [
    DataCardValue19.Value,
    DataCardValue20.Value,
    DataCardValue21.Value
    ],
    Value = true
    )
    ) = 1,
    Notify(
    "You need to select an option.",
    NotificationType.Error
    ),

    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard