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 / Setting a Choice Field...
Power Apps
Unanswered

Setting a Choice Field Based on Difference Between Two Date Fields

(0) ShareShare
ReportReport
Posted on by 29

I have a form with 2 Date fields, DateSubmitted and DateRequired. I have a SharePoint backend with a choice field of "Priority" and the choices are "Emergency" and "Normal". I want the Priority field to autopop to Emergency if the DateRequired field is < 3 days from the DateSubmitted field. Any help would be appreciated!

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @BadCode ,

    The DefaultSelectedItems (I assume this is a Combo Box) would be

    {
     Value:
     If(
     DateDiff(
     ThisItem.DateSubmitted,
     ThisItem.DateRequired,
     TimeUnit.Days
     ) < 3,
     "Emergency",
     "Normal"
     )
    }
    
    

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • BadCode Profile Picture
    29 on at

    Thanks @WarrenBelz 

     

    Now it is always on Emergency.

    It works when viewing a created form. When I'm in a new form it stays on Emergency. If I submit form and return to it, it will show correctly.

     

    Is there a way to have it update when the DateRequired is selected?

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @BadCode ,

    Just do it on FormMode

    {
     Value:
     If(
     YourFormName.Mode = FormMode.New,
     If(
     DateDiff(
     ThisItem.DateSubmitted,
     ThisItem.DateRequired,
     TimeUnit.Days
     ) < 3,
     "Emergency",
     "Normal"
     ),
     ThisItem.Priority.Value
     )
    }

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • zeg Profile Picture
    96 on at

    @BadCode 
    I think there are more details that need to be checked but for your question set DefaultSelectedItems to

    {
    Value:
    If(
    DateDiff(
    DataCardValue5.SelectedDate, // datepicker in DateSubmitted_DataCard
    DataCardValue6.SelectedDate, // datepicker in DateSelected_DataCard
    TimeUnit.Days
    ) < 3,
    "Emergency",
    "Normal"
    )
    }
    would work I guess.

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @zeg ,

    Not sure why you repeated my first post . . . 

  • zeg Profile Picture
    96 on at

    @WarrenBelz 
    I didn't.
    Your post(s including the second) is/are using "ThisItem" that I would usually use in edit or view mode.

    Mine is pointing at the controls in all modes.

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @zeg ,

    Same thing really, but I generally do not come in on posts under discussion unless they are not heading in the right direction - up to you but I would extend you the same courtesy.

  • zeg Profile Picture
    96 on at

    Not really @WarrenBelz .

     I'm new here so I'd like to ask. Does courtesy in your "Same thing really, but I generally do not come in on posts under discussion unless they are not heading in the right direction - up to you but I would extend you the same courtesy." means that I should have waited for you to figure it out? 

    And by the way, your first and second posts still don't look like they are 100% answers to the question.

    I am here to help when I can without any other intensions so I'm still not sure I understand what really bothered you.

     

  • BadCode Profile Picture
    29 on at

    Hi @WarrenBelz 

     

    Unfortunately this one does not update or show the correct Priority when returning to the record, always shows Emergency no matter what date is set. Also wanted to note that I added a ")" after "ThisItem.Priority.Value" to fix the forgotten ")".

     

    Is it common to feel dumber the more PowerApps I learn? 🙂

     

    I appreciate all the help, it's not the first time you've assisted me! I will get back to this tomorrow morning, it's past midnight here and I've been racking my brain all day. Btw, love your blog!!!

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @zeg ,

    We will leave it there as I do not want to continue the discussion on this thread, but regular responders will appreciate my thoughts.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard