The dataset has sales transactions data with transaction date.
Derive the week number of the year of each date considering the week starts from Saturday (the week start day can be considered any day in general)
In Smarten, the week is starting from Sunday. So if you derive the ‘Week of Year’ in normal scenario, it will work as follows.
Week Of Year
As per the above example, 1st Jan 2021 is Friday. So, the week of year comes under 1 whereas 3rd Jan 2021 is Sunday. Here the next week has started and so the week of year is 2 (as the week of year is starting from Sunday in Smarten as mentioned above).
1. In this example, we are considering the week start day as Saturday. So, in order to achieve the requirement, we need to subtract 6 days from the current date so as to reach the date that falls under Saturday instead of Sunday
- At first, take a copy of the current date column to perform the subtraction operation by following the steps mentioned below:
- Right-click on Date column ->Copy ->Column. A new date column will be created (the column has been renamed to ‘TransformedDate’ in the below example.)
2. To subtract 6 days from the new date column, we are using the dateAdd() function by following the steps mentioned below:
- Right click on the copied date column -> Transform -> More ->dateAdd
- Choose ‘Day’ as Argument 1, -6 as Argument 2, new date column as Argument 3.
The result will subtract 6 days from the current date as shown in the below example.
3. Now, extract the week of the year from the newly subtracted date.
- Right-click on the new Date column -> Add column -> Week of Year
Week of Year
This will give the week number of the year considering the week starts from Saturday.
Similarly, you can subtract the number of days as per the following table to start the week from any other specific day. I.e. if you want to consider the week start day like Wednesday, then subtract 3 days from the current date.
Week of Year Start from
Days to be added