Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Calculating Week Number for Financial Years

FabioP
8 - Asteroid

Dear All,

 

I'd like to use this solution but for 'Financial Year' where for example the first day of year is 2022-04-01.

Is it possible to change any part of the formula to start to count from April?

 

Ex.:

 

01/04/202252
02/04/202252
03/04/202252
04/04/202201
05/04/202201
06/04/202201
07/04/202201
08/04/202201
09/04/202201
10/04/202201
11/04/202202
12/04/202202
13/04/202202
14/04/202202
15/04/202202
8 REPLIES 8
ShankerV
17 - Castor

Hi @FabioP 

 

I am not sure whether we can achieve this with the help of a formula.

But can be achieved with the help of a manually mocked up data set.

 

Then doing a join to get the Week easily.

 

Many thanks

Shanker V

ShankerV
17 - Castor

Hi @FabioP 

 

Please find the expected output.

 

ShankerV_1-1674119252008.png

 

Many thanks

Shanker V

 

 

 

ShankerV
17 - Castor

Hi @FabioP 

 

Step 1: Input

 

ShankerV_0-1674119308216.png

 

 

Step 2: 

 

ShankerV_1-1674119326946.png

ShankerV_2-1674119338516.png

 

 

Step 3: Creating the file for our reference.

ShankerV_4-1674119407135.png

 

 

ShankerV_3-1674119386119.png

 

Many thanks

Shanker  V

 

 

 

 

Christina_H
14 - Magnetar

Try this

Mod(ToNumber(DateTimeFormat([DateKey],"%W"))-ToNumber(DateTimeFormat(ToDate(ToString(DateTimeYear([DateKey]))+"-04-01"),"%W"))+51,52)+1

Christina_H_0-1674119799346.png

 

ShankerV
17 - Castor

Hi @FabioP 

 

Step 4: Record ID tool

ShankerV_0-1674119734862.png

 

step 5:

ShankerV_1-1674119754947.png

 

IF [RecordID] = 1
THEN 1
ELSEIF MOD([RecordID],7)=1
THEN [Row-1:Week]+1
ELSE [Row-1:Week]
ENDIF

 

ShankerV_2-1674119773200.png

 

Step 6:

 

ShankerV_3-1674119814407.png

ShankerV_4-1674119857621.png

 

 

Expected output:

ShankerV_5-1674119887417.png

 

Many thanks

Shanker V

 

 

 

 

ShankerV
17 - Castor

Hi @FabioP 

 

++One more information

Use the output tool and save the output in .xlsx format.

 

So that the same can be used as input file in future where you want to find the week for any dates.

 

ShankerV_0-1674120163787.png

 

 

Many thanks

Shanker V

 

 

 

FabioP
8 - Asteroid

I just put an IF to complete with 0 when the number is between 1 - 9 and create a new formula for who needs the week starting on Sunday:

 

Starting Mon

IIF(Length(ToString(Mod(ToNumber(DateTimeFormat([Date],"%W")) - ToNumber(DateTimeFormat(
ToString( DateTimeYear([Date])) + "-04-01","%W")) + 51, 52) +1)) = 1,

'0'+ ToString(Mod(ToNumber(DateTimeFormat([Date],"%W")) - ToNumber(DateTimeFormat(
ToString( DateTimeYear([Date])) + "-04-01","%W")) + 51, 52) +1),

ToString(Mod(ToNumber(DateTimeFormat([Date],"%W")) - ToNumber(DateTimeFormat(
ToString( DateTimeYear([Date])) + "-04-01","%W")) + 51, 52) +1))

 

Starting Sun

IIF(Length(ToString(Mod(ToNumber(PadLeft(ToString(FLOOR(DateTimeDiff(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),DateTimeParse(ToString(ToNumber(DateTimeFormat(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),"%Y")))+'-01-01',"%Y-%m-%d"),"days")/ 7)+ 1),2,"0"))-ToNumber(DateTimeFormat(ToDate(ToString(DateTimeYear([Date]))+"-04-01"),"%W"))+51,52)+1)) = 1,

'0'+ToString(Mod(ToNumber(PadLeft(ToString(FLOOR(DateTimeDiff(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),DateTimeParse(ToString(ToNumber(DateTimeFormat(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),"%Y")))+'-01-01',"%Y-%m-%d"),"days")/ 7)+ 1),2,"0"))-ToNumber(DateTimeFormat(ToDate(ToString(DateTimeYear([Date]))+"-04-01"),"%W"))+51,52)+1),

ToString(Mod(ToNumber(PadLeft(ToString(FLOOR(DateTimeDiff(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),DateTimeParse(ToString(ToNumber(DateTimeFormat(DateTimeAdd([Date],4 - Switch(DateTimeFormat([Date],"%a"),7,"Sun",1,"Mon",2,"Tue",3,"Wed",4,"Thu",5,"Fri",6),"days"),"%Y")))+'-01-01',"%Y-%m-%d"),"days")/ 7)+ 1),2,"0"))-ToNumber(DateTimeFormat(ToDate(ToString(DateTimeYear([Date]))+"-04-01"),"%W"))+51,52)+1))

Christina_H
14 - Magnetar

@FabioP Take a look at this page for all the date-time specifiers:

DateTime Functions | Alteryx Help

 

You can substitute %U for %W to get weeks starting on a Sunday.

Labels
Top Solution Authors