Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
supportcenter
Contributor II
Contributor II

First weekday of the next month based on the provided date.

Anyone have a better way to do this?

Here is what I am using currently:

=IF( NUM(WEEKDAY(MONTHEND(vDate)+1)) >4
, DATE(((MONTHEND(vDate)+1) - NUM(WEEKDAY(MONTHEND(vDate)+1)))+7)
, DATE(MONTHEND(vDate)+1) )

The 'vDate' is the variable assigned to an Input Box.

1 Solution

Accepted Solutions
supportcenter
Contributor II
Contributor II
Author

FYI, I have noted an error in my original calculation and have now corrected it. I also removed MONTHEND in favor of MONTHSTART. My question still stands though. Is there a better way to do this?

 

IF( NUM( WEEKDAY( MONTHSTART( vDate, 1 ) ) ) >4
, DATE( MONTHSTART( vDate, 1 ) + FABS( WEEKDAY( MONTHSTART( vDate, 1 ) ) - 7 ) )
, MONTHSTART( vDate, 1 ) )

 

Again, the 'vDate' is the variable assigned to an Input Box.

 

 

 

View solution in original post

4 Replies
MindaugasBacius
Partner - Specialist III
Partner - Specialist III

You could try this:

=Alt(Pick(Weekday(MonthStart(vDate, 1)) + 1, 0, 1, 2, 3, 4), 0)

Brett_Bleess
Former Employee
Former Employee

Hey guys, did Mindaugas' post help you with this?  If so, do not forget to come back to the thread and use the Accept as Solution button on it to give him credit for the assistance and to let other Community Members know it did work.  If you are still working on things, leave an update on what you need.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
supportcenter
Contributor II
Contributor II
Author

That solution assigns Saturday and Sunday as well as Monday as 0. I am having trouble understanding how this will get me to  the first weekday of the next month based on the provided date.

if vDate = 1/20/2020 then the first weekday of the next month would be Monday 2/3/2020. Getting to the 2/3/2020 date is what I want to calculate.

supportcenter
Contributor II
Contributor II
Author

FYI, I have noted an error in my original calculation and have now corrected it. I also removed MONTHEND in favor of MONTHSTART. My question still stands though. Is there a better way to do this?

 

IF( NUM( WEEKDAY( MONTHSTART( vDate, 1 ) ) ) >4
, DATE( MONTHSTART( vDate, 1 ) + FABS( WEEKDAY( MONTHSTART( vDate, 1 ) ) - 7 ) )
, MONTHSTART( vDate, 1 ) )

 

Again, the 'vDate' is the variable assigned to an Input Box.