Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
qvqfqlik
Creator
Creator

min max dates

i need to find min and max dates for current week

LET vCW = peek('CYW',0,'table1');

LET vMinCurrentWk = (WeekStart($(vCW))));

LET vMaxCurrentWk = WeekDay(WeekEnd($(vCW)));

please help

vCW is returning  current yearweek. No issue with this. But need to find min and max of current week.

20 Replies
tresesco
MVP
MVP

How does your vCW (current yearweek) value look like? Is it a string or number?

swuehl
MVP
MVP

What's the format of your yearweek value?  'YYYYWW'?

You can use

MakeWeekDate(YYYY [ , WW [ , D ] ] )

function to create a date from your yearweek value:


LET vMinCurrentWk = MakeWeekDate(Left('$(vCW)',4),Right('$(vCW)',2));

LET vMaxCurrentWk = WeekDay(WeekEnd(MakeWeekDate(Left('$(vCW)',4),Right('$(vCW)',2))));


qvqfqlik
Creator
Creator
Author

vCW looks like  '201628' , i.e like  'YYYYWK'  yearweek

I want to get min and max dates for current week.

table1:

  NoConcatenate

  LOAD

  yrwk as CYW

  Resident CAL

  Order By@@

  calYRWK

  ;

LET vCW= peek('CYW',0,'table1');

LET vMindateCWk = ?

LET vMaxdateCtWk = ?

please help

swuehl
MVP
MVP

Have you tried something like I've suggested above, using MakeWeekDate() function?

LET vMindateCWk = MakeWeekDate(Left('$(vCW)',4),Right('$(vCW)',2));

LET vMaxdateCtWk = DayName(WeekEnd(MakeWeekDate(Left('$(vCW)',4),Right('$(vCW)',2))));

maxgro
MVP
MVP

Maybe

WeekStart(MakeWeekDate(left('201628', 4), Right('201628', 2)))

WeekEnd(MakeWeekDate(left('201628', 4), Right('201628', 2)))

Replace 201628 with your field or variable

1.png

WeekStart/End return a timestamp

qvqfqlik
Creator
Creator
Author

this will work only for  201628 , I guess what @swuehl  solution  will work, but I wan the Min date to start from Sunday, and Max date to be Saturday.  Like current week would be  Sun to Sat

qvqfqlik
Creator
Creator
Author

Min date is 7/11/2016 which is monday...and max date is 7/17/2016

I need min date to start from Sunday

Also, within  the script, how to calculatea metric for  (current week + next 3 weeks) data -> next 3 weeks should be updated everyday. Please help

swuehl
MVP
MVP

MakeWeekDate() function uses ISO weeks.

If your week numbering matches ISO weeks, with just start of week being Sunday, you can just subtract 1 from the date that MakeWeekDate() returns (QlikView uses internally integer numbers to represent dates).

See also

Redefining the Week Start

Redefining the Week Numbers

Redefining the Week Start in Qlik Sense

vinieme12
Champion III
Champion III

If you need current weeks date why peek in to a table row?

LEt vMinWeekDate = WeekStart(now(),0,6);  //Mondays Date

LEt vMaxWeekDate = WeekEnd(now(),0,6);  // Sundays Date

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.