cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
roli_
Level: Powered On

Splitting weeks falling into two months

I am currently using the following formula to find the first day of a week from a date picker:
DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)

(Weeks starts on a Monday in Europe).

 

This works fine, but I am struggling to find the first day of a week if you select  Wednesday 2 January 2019 for instance. My command would of course return Monday 31. December 2018, but I would like first day of the week in the same month to be reurned, Tuesday 1. January 2019.

 

Hope that makes sense and that someone can help me in the right direction.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Splitting weeks falling into two months

Hi @roli_,

Based on the needs that you mentioned, I have made a test on my side, please take a try with the following workaround:7.JPG

Set the Text property of the Label control to following:

If(
    Year(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Year(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), 1, 1)
)

Please check the attached GIF screenshot for more details:

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support Team
Community Support Team

Re: Splitting weeks falling into two months

Hi @roli_,

Based on the needs that you mentioned, I have made a test on my side, please take a try with the following workaround:7.JPG

Set the Text property of the Label control to following:

If(
    Year(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Year(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), 1, 1)
)

Please check the attached GIF screenshot for more details:

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
roli_
Level: Powered On

Re: Splitting weeks falling into two months

 

Thanks Kris,


Your function only works for January as you are comparing year instead of months. I used your logic and changed to the Month function instead of the Year function. So the working function is:

If(
    Month(DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero)) = Month(DatePicker1.SelectedDate),
    DatePicker1.SelectedDate - Weekday(DatePicker1.SelectedDate, MondayZero),
    Date(Year(DatePicker1.SelectedDate), Month(DatePicker1.SelectedDate), 1)
)

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

Follow PowerApps on Twitter

Stay Up-to-Date by following PowerApps on Twitter

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 38 members 4,079 guests
Please welcome our newest community members: