Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
AndersGS
Contributor III
Contributor III

First day of last week last year

Hi guys,

I have successfully used this expression to get the first day of last week last year:

=WeekStart(MakeWeekDate(year(today())-1,week(today()),0)-1)

but when using this expression today I get 2019-12-30 rather than 2020-01-06 because the week numbers differ 2020 vs 2021

any ideas on how to alter this formula to get it right?

Running QlikView 11.20 SR 18

Thanks,
Anders

Labels (5)
1 Solution

Accepted Solutions
chrismarlow
Specialist II
Specialist II

Hi,

This feels a bit hardcoded, but I think you always want to go 53 weeks back from the first day of the current week, so maybe =Date(today()-weekday(today())-(53*7))?

Cheers,

Chris.

View solution in original post

4 Replies
Frank_Hartmann
Master II
Master II

Frank_Hartmann_0-1610368018585.png

 

AndersGS
Contributor III
Contributor III
Author

Thanks Frank_Hartmann. That solution works this year because last year was a leap year, but next year it won't.
I'd rather have an dynamic expression that takes that into account.

For example =WeekStart(MakeWeekDate(year('2022-01-10')-1,week('2022-01-10'),0)) will show '2021-01-11' rather than 2021-01-04

chrismarlow
Specialist II
Specialist II

Hi,

This feels a bit hardcoded, but I think you always want to go 53 weeks back from the first day of the current week, so maybe =Date(today()-weekday(today())-(53*7))?

Cheers,

Chris.

AndersGS
Contributor III
Contributor III
Author

Great, thanks Chris - that does the trick!