Alert: There is a planned Community maintenance outage October 16th from approximately 10 - 11 PM PST. During this time the Alteryx Community will be inaccessible. Thank you for your understanding!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

How to calculate Last week Number

Sarita_Kumari
6 - Meteoroid

Hi All,

 

How should I calculate Last week number 

 

E.g If the Date is 2020-02-01 week number should be 4 and year should be 2021

 

  If the Date is 2020-01-04 week number should be 53 and year should be 2020

3 REPLIES 3
afv2688
16 - Nebula
16 - Nebula

Hello @Sarita_Kumari ,

 

Try using this on the formula tool:

 

 

IIF(ToNumber(DateTimeFormat([Field1],'%j'))<=7,
ToNumber(DateTimeFormat(DateTimeAdd([Field1],-7,'days'),'%W'))+1,
ToNumber(DateTimeFormat([Field1],'%W')))

 

 

Edit: This formula takes the current week except if the calculation refers to last year. If that happens it calculates the last years week by subtracting a whole week and adding then 1.

 

The counter starts at 0, therefore there is no need to subtract.

 

Regards

Sarita_Kumari
6 - Meteoroid

Hi,

 

Thanks for your reply. But I am looking for previous week number for current Date also.

afv2688
16 - Nebula
16 - Nebula

Hello @Sarita_Kumari ,

 

If you want the result to show it for the previous week using the current date you have only to change the field parameter:

 

 

IIF(ToNumber(DateTimeFormat(DateTimeNow(),'%j'))<=7,
ToNumber(DateTimeFormat(DateTimeAdd(DateTimeNow(),-7,'days'),'%W'))+1,
ToNumber(DateTimeFormat(DateTimeNow(),'%W')))

 

 

Given that Alteryx counts the weeks of the year starting by 0, on the counter, 2020-02-01 for alteryx belongs to the 4th week (4 weeks plus week 0).

 

So there is no need to subtract a week since it is already giving you the value you are looking for.

 

Untitled.png

 

Regards

Labels