Define start of fiscal year
I can use the function yearweek() to define the week number within the year, but that does not sync with my employer’s fiscal year, which begins on the first Monday of the new year.
I am looking for a solution to determine the week of the year, with the first week beginning on the first Monday of the new year. Each new pay period/week begins on Monday (first day of the week is Monday and the last day of the week is Sunday).
It would be nice if I could define the Fiscal Year as a global function that could be used throughout the database.
Would like to return the Fiscal Year Week Number like this: YYYY-WW (as in 2022-01)
Thanks,
Chris
8 replies
-
You need to create a table storing the year and a number of ‘offset’ days. This is the number of days before the first Monday of that year. So:
2022=2 offset days
2023=1 offset days
2024=0
2025=5
2026=4
2027=3
and so on.
Then for any given date, I’ll call it ‘tempDate’, look up year(tempDate) in the new table by using the select command to get the offset days for that year. The correct week number for your fiscal year for any tempDate is:
let fiscalYearWeek:=yearweek(tempDate-offset)
I haven’t tested but should work in theory. Let me know!
-
Thanks Paul. I’ll try it out!
-
I guess I need help with the syntax of looking up the year(tempDate) using the select command.
I have created a Table called ‘FiscalYear Offset Days’
The table consists of two fields: ‘Calendar Year’ (a date field that I just put January 1, YYYY) and ‘Offset Days’ (number field with the number of offset days).
-
I’ve been trying to figure out a look up formula for a few hours and can’t seem to figure it out. Obviously, the magic happens within…
“…look up year(tempDate) in the new table by using the select command to get the offset days for that year.”
I’ve tried…
let offset := select FiscalYear.’Calendar Year” = year(tempYear)
let offset := select FiscalYear.’Offset Days’ where 'Calendar Year'= year(tempYear)
and many other combinations, but mostly just getting error messages and nothing returning the offset value.
How do I use the select command to look up the information in the look up table and return the offset value?
-
Okay, I am finally able to look up and display the offset days with the following script, where ‘Pay Period End’ is a date field for the start of the pay period (which should always be a Monday); FiscalYear is the look up table; ‘Calendar Year Number’ is a number field with the appropriate year typed in; ‘Offset Days’ is a number field for the number of days before the first Monday of that year.
let tempDate := year('Pay Period Start'); let offset := (select FiscalYear)['Calendar Year Number' = tempDate].'Offset Days';
but…
let fiscalYearWeek:=yearweek(tempDate-offset)
Results in the error
invalid operator: date - [number] at line 3 column 56
I’m continuing to see if I can figure it out!
-
Actually,
let fiscalYearWeek:=yearweek(tempDate-offset)
should actually be…
let fiscalYearWeek := yearweek(‘Pay Period Start’ - offset)
but I still get the same invalid operator error.
-
Figure it out!
let tempDate := year('Pay Period End'); let offset := (select FiscalYear)['Calendar Year Number' = tempDate].'Offset Days'; let offsetN := number(offset); let FiscalYearWeek := yearweek('Pay Period End' - offsetN); FiscalYearWeek
However, the offset number in the look up table ‘FiscalYear’ needs to be adjusted differently than first suggested. It seems that Ninox uses a Week Number system that says that the first week of the year with a majority of days in the new year is week 1. So if January 1st falls on a Sunday, Monday, Tuesday, or Wednesday, then that is Week 1. However if January 1st falls on a Thursday, Friday, or Saturday, then Week 1 is the following week.
After figuring that out, I realized that if January 1st fell after Wednesday, I needed to use a negative number for the offset number.
2019 is +6
2020 is +5
2021 is -3
2022 is -2
2023 is -1
2024 is -3
2025 is +5
I have it figured out up to 2030, but can always add more as needed.
Thanks for the help in getting me started, Paul. If anyone comes up with a more elegant solution, please post it for all to see.
Chris
Content aside
- Status Answered
- 2 yrs agoLast active
- 8Replies
- 87Views
-
2
Following