cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Cooper01
Responsive Resident
Responsive Resident

Generate last date of a given weekday?

I am trying to create a gallery of a date range that starts on a specific day of the week. The start date is dynamic and is stored as a weekday name ("Wednesday" for example). Is there any way in PowerApps to create a most recent date from that value?

So for example, as today is Monday 12/2/2019, and the start date is Wednesday, I want to get the date Wednesday 12/27/2019. If start date were Monday instead of Wednesday, I want to get the date Monday 12/2/2019 (today). Is this possible?

1 ACCEPTED SOLUTION

Accepted Solutions

@Cooper01 

I worked really hard on this one and it nearly broke me.  My solution shows how the problem can be solved but I left out the gallery part.  I think you can figure out the rest from here.

Suggest you practice by recreating my app.  Make a screen that looks like this.

 

Capture2.PNG

 

Put this code in the Items property of Dropdown_Day.

 

["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

 

Put this code in the Text property of Label_Result.

 

DateAdd(
    DatePicker_Date.SelectedDate,
        Switch(
             Weekday(DatePicker_Date.SelectedDate,Monday),
             1,Weekday(DatePicker_Date.SelectedDate,Monday),
             2,Weekday(DatePicker_Date.SelectedDate,Tuesday),
             3,Weekday(DatePicker_Date.SelectedDate,Wednesday),
             4,Weekday(DatePicker_Date.SelectedDate,Thursday),
             5,Weekday(DatePicker_Date.SelectedDate,Friday),
             6,Weekday(DatePicker_Date.SelectedDate,Saturday),
             7,Weekday(DatePicker_Date.SelectedDate,Sunday)
        )-
        Switch(
             Dropdown_Day.Selected.Value,
             "Monday",Weekday(DatePicker_Date.SelectedDate,Monday),
             "Tuesday",Weekday(DatePicker_Date.SelectedDate,Tuesday),
             "Wednesday",Weekday(DatePicker_Date.SelectedDate,Wednesday),
             "Thursday",Weekday(DatePicker_Date.SelectedDate,Thursday),
             "Friday",Weekday(DatePicker_Date.SelectedDate,Friday),
             "Saturday",Weekday(DatePicker_Date.SelectedDate,Saturday),
             "Sunday",Weekday(DatePicker_Date.SelectedDate,Sunday)
        ),
    Days
)

 

Now you can play around with the inputs to test the dates being output.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

View solution in original post

3 REPLIES 3
mdevaney
Super User III
Super User III

@Cooper01

I find the example that was given somewhat confusing.  Could you please share several examples in this format?

 

Weekday InputDate Ouput
  
  
  
  
  
Cooper01
Responsive Resident
Responsive Resident

Sure, general format is most recent date (including today) of a given weekday:

Today isWeekday InputDate Output
12/2/2019Monday12/2/2019
12/2/2019Tuesday11/26/2019
12/2/2019Wednesday11/27/2019
12/2/2019Saturday11/30/2019
12/2/2019Sunday12/1/2019

 

Today isWeekday InputDate Output
12/3/2019Monday12/2/2019
12/3/2019Tuesday12/3/2019
12/3/2019Wednesday11/27/2019
12/3/2019Saturday11/30/2019
12/3/2019Sunday12/1/2019

 

@Cooper01 

I worked really hard on this one and it nearly broke me.  My solution shows how the problem can be solved but I left out the gallery part.  I think you can figure out the rest from here.

Suggest you practice by recreating my app.  Make a screen that looks like this.

 

Capture2.PNG

 

Put this code in the Items property of Dropdown_Day.

 

["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

 

Put this code in the Text property of Label_Result.

 

DateAdd(
    DatePicker_Date.SelectedDate,
        Switch(
             Weekday(DatePicker_Date.SelectedDate,Monday),
             1,Weekday(DatePicker_Date.SelectedDate,Monday),
             2,Weekday(DatePicker_Date.SelectedDate,Tuesday),
             3,Weekday(DatePicker_Date.SelectedDate,Wednesday),
             4,Weekday(DatePicker_Date.SelectedDate,Thursday),
             5,Weekday(DatePicker_Date.SelectedDate,Friday),
             6,Weekday(DatePicker_Date.SelectedDate,Saturday),
             7,Weekday(DatePicker_Date.SelectedDate,Sunday)
        )-
        Switch(
             Dropdown_Day.Selected.Value,
             "Monday",Weekday(DatePicker_Date.SelectedDate,Monday),
             "Tuesday",Weekday(DatePicker_Date.SelectedDate,Tuesday),
             "Wednesday",Weekday(DatePicker_Date.SelectedDate,Wednesday),
             "Thursday",Weekday(DatePicker_Date.SelectedDate,Thursday),
             "Friday",Weekday(DatePicker_Date.SelectedDate,Friday),
             "Saturday",Weekday(DatePicker_Date.SelectedDate,Saturday),
             "Sunday",Weekday(DatePicker_Date.SelectedDate,Sunday)
        ),
    Days
)

 

Now you can play around with the inputs to test the dates being output.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (86,683)