473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calendar year versus Fiscal year

rcollins
234 100+
I have a query that puts dates into quarters ofr me. The problem is that it puts it into jan-mar as quarter one. I need jul-sep of 2008 to be q1 2009 and jan-mar to be q3 2009. Any ideas?
Mar 31 '09 #1
19 6267
ADezii
8,834 Expert 8TB
@rcollins
You can use the combination of a Query with a Calculated Field, that returns the proper Quarter via a Public Function. I used the Orders Table of the Northwind Database for this demo:
  • Query with Calculated Field:
    Expand|Select|Wrap|Line Numbers
    1. SELECT Orders.ShippedDate, fCalcQuarters([ShippedDate]) AS Quarter
    2. FROM Orders
    3. WHERE (((Orders.ShippedDate) Between #6/1/1997# And #5/31/1998#))
    4. ORDER BY fCalcQuarters([ShippedDate]);
    5.  
  • Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCalcQuarters(dteShipDate As Date)
    2. If dteShipDate >= #6/1/1997# And dteShipDate <= #8/31/1997# Then
    3.   fCalcQuarters = "Q1"
    4. ElseIf dteShipDate >= #9/1/1997# And dteShipDate <= #11/30/1997# Then
    5.   fCalcQuarters = "Q2"
    6. ElseIf dteShipDate >= #12/1/1997# And dteShipDate <= #2/28/1998# Then
    7.   fCalcQuarters = "Q3"
    8. ElseIf dteShipDate >= #3/1/1998# And dteShipDate <= #5/30/1998# Then
    9.   fCalcQuarters = "Q4"
    10. Else
    11.   fCalcQuarters = Null
    12. End If
    13. End Function
    14.  
  • Sample Output:
    Expand|Select|Wrap|Line Numbers
    1. Shipped Date Quarter
    2. 31-Jul-1997    Q1
    3. 18-Jul-1997    Q1
    4. 07-Aug-1997    Q1
    5. 06-Aug-1997    Q1
    6. 06-Aug-1997    Q1
    7. 05-Aug-1997    Q1
    8. 04-Aug-1997    Q1
    9. 01-Aug-1997    Q1
    10. 01-Aug-1997    Q1
    11. 01-Aug-1997    Q1
    12. 08-Aug-1997    Q1
    13. 01-Aug-1997    Q1
    14. 11-Aug-1997    Q1
    15. 30-Jul-1997    Q1
    16. 29-Jul-1997    Q1
    17. 29-Jul-1997    Q1
    18. 25-Jul-1997    Q1
    19. 25-Jul-1997    Q1
    20. 22-Jul-1997    Q1
    21. 22-Jul-1997    Q1
    22. 21-Jul-1997    Q1
    23. 21-Jul-1997    Q1
    24. 18-Jul-1997    Q1
    25. 01-Aug-1997    Q1
    26. 20-Aug-1997    Q1
    27. 02-Jun-1997    Q1
    28. 29-Aug-1997    Q1
    29. 28-Aug-1997    Q1
    30. 27-Aug-1997    Q1
    31. 26-Aug-1997    Q1
    32. 26-Aug-1997    Q1
    33. 26-Aug-1997    Q1
    34. 21-Aug-1997    Q1
    35. 21-Aug-1997    Q1
    36. 08-Aug-1997    Q1
    37. 20-Aug-1997    Q1
    38. 12-Aug-1997    Q1
    39. 20-Aug-1997    Q1
    40. 19-Aug-1997    Q1
    41. 19-Aug-1997    Q1
    42. 19-Aug-1997    Q1
    43. 18-Aug-1997    Q1
    44. 15-Aug-1997    Q1
    45. 14-Aug-1997    Q1
    46. 14-Aug-1997    Q1
    47. 12-Aug-1997    Q1
    48. 11-Aug-1997    Q1
    49. 21-Aug-1997    Q1
    50. 06-Jun-1997    Q1
    51. 20-Jun-1997    Q1
    52. 19-Jun-1997    Q1
    53. 18-Jun-1997    Q1
    54. 18-Jun-1997    Q1
    55. 17-Jun-1997    Q1
    56. 16-Jun-1997    Q1
    57. 13-Jun-1997    Q1
    58. 13-Jun-1997    Q1
    59. 13-Jun-1997    Q1
    60. 24-Jun-1997    Q1
    61. 09-Jun-1997    Q1
    62. 12-Jun-1997    Q1
    63. 06-Jun-1997    Q1
    64. 06-Jun-1997    Q1
    65. 06-Jun-1997    Q1
    66. 05-Jun-1997    Q1
    67. 05-Jun-1997    Q1
    68. 04-Jun-1997    Q1
    69. 03-Jun-1997    Q1
    70. 02-Jun-1997    Q1
    71. 16-Jul-1997    Q1
    72. 13-Aug-1997    Q1
    73. 10-Jun-1997    Q1
    74. 14-Jul-1997    Q1
    75. 16-Jul-1997    Q1
    76. 09-Jun-1997    Q1
    77. 16-Jul-1997    Q1
    78. 25-Jun-1997    Q1
    79. 14-Jul-1997    Q1
    80. 14-Jul-1997    Q1
    81. 14-Jul-1997    Q1
    82. 11-Jul-1997    Q1
    83. 10-Jul-1997    Q1
    84. 10-Jul-1997    Q1
    85. 09-Jul-1997    Q1
    86. 09-Jul-1997    Q1
    87. 09-Jul-1997    Q1
    88. 30-Jun-1997    Q1
    89. 04-Jul-1997    Q1
    90. 26-Jun-1997    Q1
    91. 30-Jun-1997    Q1
    92. 30-Jun-1997    Q1
    93. 30-Jun-1997    Q1
    94. 01-Jul-1997    Q1
    95. 04-Jul-1997    Q1
    96. 04-Jul-1997    Q1
    97. 04-Jul-1997    Q1
    98. 02-Jul-1997    Q1
    99. 05-Nov-1997    Q2
    100. 30-Oct-1997    Q2
    101. 31-Oct-1997    Q2
    102. 31-Oct-1997    Q2
    103. 04-Nov-1997    Q2
    104. 07-Nov-1997    Q2
    105. 05-Nov-1997    Q2
    106. 05-Nov-1997    Q2
    107. 07-Nov-1997    Q2
    108. 29-Oct-1997    Q2
    109. 23-Oct-1997    Q2
    110. 05-Nov-1997    Q2
    111. 05-Nov-1997    Q2
    112. 29-Oct-1997    Q2
    113. 29-Oct-1997    Q2
    114. 29-Oct-1997    Q2
    115. 27-Oct-1997    Q2
    116. 21-Oct-1997    Q2
    117. 24-Oct-1997    Q2
    118. 23-Oct-1997    Q2
    119. 22-Oct-1997    Q2
    120. 21-Oct-1997    Q2
    121. 17-Oct-1997    Q2
    122. 20-Oct-1997    Q2
    123. 28-Nov-1997    Q2
    124. 10-Nov-1997    Q2
    125. 27-Oct-1997    Q2
    126. 21-Nov-1997    Q2
    127. 26-Sep-1997    Q2
    128. 16-Oct-1997    Q2
    129. 28-Nov-1997    Q2
    130. 28-Nov-1997    Q2
    131. 27-Nov-1997    Q2
    132. 27-Nov-1997    Q2
    133. 26-Nov-1997    Q2
    134. 25-Nov-1997    Q2
    135. 25-Nov-1997    Q2
    136. 24-Nov-1997    Q2
    137. 24-Nov-1997    Q2
    138. 27-Nov-1997    Q2
    139. 21-Nov-1997    Q2
    140. 11-Nov-1997    Q2
    141. 21-Nov-1997    Q2
    142. 20-Nov-1997    Q2
    143. 18-Nov-1997    Q2
    144. 18-Nov-1997    Q2
    145. 18-Nov-1997    Q2
    146. 18-Nov-1997    Q2
    147. 18-Nov-1997    Q2
    148. 17-Nov-1997    Q2
    149. 14-Nov-1997    Q2
    150. 14-Nov-1997    Q2
    151. 14-Nov-1997    Q2
    152. 12-Nov-1997    Q2
    153. 21-Nov-1997    Q2
    154. 10-Sep-1997    Q2
    155. 22-Sep-1997    Q2
    156. 19-Sep-1997    Q2
    157. 19-Sep-1997    Q2
    158. 19-Sep-1997    Q2
    159. 19-Sep-1997    Q2
    160. 18-Sep-1997    Q2
    161. 18-Sep-1997    Q2
    162. 17-Sep-1997    Q2
    163. 15-Sep-1997    Q2
    164. 15-Sep-1997    Q2
    165. 11-Sep-1997    Q2
    166. 22-Sep-1997    Q2
    167. 11-Sep-1997    Q2
    168. 03-Sep-1997    Q2
    169. 10-Sep-1997    Q2
    170. 09-Sep-1997    Q2
    171. 08-Sep-1997    Q2
    172. 08-Sep-1997    Q2
    173. 05-Sep-1997    Q2
    174. 03-Sep-1997    Q2
    175. 03-Sep-1997    Q2
    176. 16-Oct-1997    Q2
    177. 02-Sep-1997    Q2
    178. 26-Sep-1997    Q2
    179. 01-Sep-1997    Q2
    180. 01-Sep-1997    Q2
    181. 11-Sep-1997    Q2
    182. 14-Oct-1997    Q2
    183. 02-Sep-1997    Q2
    184. 23-Sep-1997    Q2
    185. 14-Oct-1997    Q2
    186. 14-Oct-1997    Q2
    187. 13-Oct-1997    Q2
    188. 13-Oct-1997    Q2
    189. 10-Oct-1997    Q2
    190. 09-Oct-1997    Q2
    191. 08-Oct-1997    Q2
    192. 07-Oct-1997    Q2
    193. 07-Oct-1997    Q2
    194. 03-Oct-1997    Q2
    195. 03-Oct-1997    Q2
    196. 29-Sep-1997    Q2
    197. 24-Sep-1997    Q2
    198. 15-Oct-1997    Q2
    199. 03-Oct-1997    Q2
    200. 23-Sep-1997    Q2
    201. 15-Oct-1997    Q2
    202. 30-Sep-1997    Q2
    203. 30-Sep-1997    Q2
    204. 30-Sep-1997    Q2
    205. 30-Sep-1997    Q2
    206. 01-Oct-1997    Q2
    207. 01-Oct-1997    Q2
    208. 26-Sep-1997    Q2
    209. 31-Dec-1997    Q3
    210. 26-Dec-1997    Q3
    211. 26-Dec-1997    Q3
    212. 26-Dec-1997    Q3
    213. 25-Dec-1997    Q3
    214. 24-Dec-1997    Q3
    215. 23-Dec-1997    Q3
    216. 05-Jan-1998    Q3
    217. 22-Dec-1997    Q3
    218. 22-Dec-1997    Q3
    219. 24-Dec-1997    Q3
    220. 31-Dec-1997    Q3
    221. 31-Dec-1997    Q3
    222. 01-Jan-1998    Q3
    223. 02-Jan-1998    Q3
    224. 02-Jan-1998    Q3
    225. 05-Jan-1998    Q3
    226. 05-Jan-1998    Q3
    227. 05-Jan-1998    Q3
    228. 05-Jan-1998    Q3
    229. 19-Dec-1997    Q3
    230. 09-Dec-1997    Q3
    231. 06-Jan-1998    Q3
    232. 02-Jan-1998    Q3
    233. 10-Dec-1997    Q3
    234. 07-Jan-1998    Q3
    235. 07-Jan-1998    Q3
    236. 02-Dec-1997    Q3
    237. 03-Dec-1997    Q3
    238. 04-Dec-1997    Q3
    239. 05-Dec-1997    Q3
    240. 05-Dec-1997    Q3
    241. 08-Dec-1997    Q3
    242. 08-Dec-1997    Q3
    243. 08-Dec-1997    Q3
    244. 12-Dec-1997    Q3
    245. 09-Dec-1997    Q3
    246. 19-Dec-1997    Q3
    247. 12-Dec-1997    Q3
    248. 12-Dec-1997    Q3
    249. 15-Dec-1997    Q3
    250. 15-Dec-1997    Q3
    251. 15-Dec-1997    Q3
    252. 16-Dec-1997    Q3
    253. 17-Dec-1997    Q3
    254. 18-Dec-1997    Q3
    255. 19-Dec-1997    Q3
    256. 19-Dec-1997    Q3
    257. 09-Dec-1997    Q3
    258. 09-Feb-1998    Q3
    259. 13-Feb-1998    Q3
    260. 12-Feb-1998    Q3
    261. 12-Feb-1998    Q3
    262. 12-Feb-1998    Q3
    263. 12-Feb-1998    Q3
    264. 12-Feb-1998    Q3
    265. 11-Feb-1998    Q3
    266. 11-Feb-1998    Q3
    267. 10-Feb-1998    Q3
    268. 04-Feb-1998    Q3
    269. 10-Feb-1998    Q3
    270. 16-Feb-1998    Q3
    271. 09-Feb-1998    Q3
    272. 09-Feb-1998    Q3
    273. 09-Feb-1998    Q3
    274. 06-Feb-1998    Q3
    275. 06-Feb-1998    Q3
    276. 06-Feb-1998    Q3
    277. 05-Feb-1998    Q3
    278. 04-Feb-1998    Q3
    279. 04-Feb-1998    Q3
    280. 04-Feb-1998    Q3
    281. 10-Feb-1998    Q3
    282. 20-Feb-1998    Q3
    283. 07-Jan-1998    Q3
    284. 27-Feb-1998    Q3
    285. 27-Feb-1998    Q3
    286. 27-Feb-1998    Q3
    287. 26-Feb-1998    Q3
    288. 26-Feb-1998    Q3
    289. 25-Feb-1998    Q3
    290. 23-Feb-1998    Q3
    291. 23-Feb-1998    Q3
    292. 23-Feb-1998    Q3
    293. 13-Feb-1998    Q3
    294. 20-Feb-1998    Q3
    295. 16-Feb-1998    Q3
    296. 19-Feb-1998    Q3
    297. 19-Feb-1998    Q3
    298. 19-Feb-1998    Q3
    299. 18-Feb-1998    Q3
    300. 18-Feb-1998    Q3
    301. 18-Feb-1998    Q3
    302. 18-Feb-1998    Q3
    303. 17-Feb-1998    Q3
    304. 17-Feb-1998    Q3
    305. 20-Feb-1998    Q3
    306. 20-Feb-1998    Q3
    307. 14-Jan-1998    Q3
    308. 21-Jan-1998    Q3
    309. 20-Jan-1998    Q3
    310. 19-Jan-1998    Q3
    311. 19-Jan-1998    Q3
    312. 19-Jan-1998    Q3
    313. 16-Jan-1998    Q3
    314. 16-Jan-1998    Q3
    315. 15-Jan-1998    Q3
    316. 14-Jan-1998    Q3
    317. 14-Jan-1998    Q3
    318. 21-Jan-1998    Q3
    319. 14-Jan-1998    Q3
    320. 13-Jan-1998    Q3
    321. 13-Jan-1998    Q3
    322. 13-Jan-1998    Q3
    323. 12-Jan-1998    Q3
    324. 09-Jan-1998    Q3
    325. 09-Jan-1998    Q3
    326. 09-Jan-1998    Q3
    327. 08-Jan-1998    Q3
    328. 03-Feb-1998    Q3
    329. 23-Feb-1998    Q3
    330. 08-Jan-1998    Q3
    331. 14-Jan-1998    Q3
    332. 30-Jan-1998    Q3
    333. 02-Feb-1998    Q3
    334. 02-Feb-1998    Q3
    335. 12-Jan-1998    Q3
    336. 21-Jan-1998    Q3
    337. 03-Feb-1998    Q3
    338. 02-Feb-1998    Q3
    339. 30-Jan-1998    Q3
    340. 30-Jan-1998    Q3
    341. 30-Jan-1998    Q3
    342. 30-Jan-1998    Q3
    343. 29-Jan-1998    Q3
    344. 22-Jan-1998    Q3
    345. 23-Jan-1998    Q3
    346. 30-Jan-1998    Q3
    347. 29-Jan-1998    Q3
    348. 23-Jan-1998    Q3
    349. 23-Jan-1998    Q3
    350. 23-Jan-1998    Q3
    351. 23-Jan-1998    Q3
    352. 23-Jan-1998    Q3
    353. 21-Jan-1998    Q3
    354. 26-Jan-1998    Q3
    355. 26-Jan-1998    Q3
    356. 29-Jan-1998    Q3
    357. 14-Apr-1998    Q4
    358. 15-Apr-1998    Q4
    359. 15-Apr-1998    Q4
    360. 13-Apr-1998    Q4
    361. 16-Apr-1998    Q4
    362. 13-Apr-1998    Q4
    363. 14-Apr-1998    Q4
    364. 16-Apr-1998    Q4
    365. 16-Apr-1998    Q4
    366. 17-Apr-1998    Q4
    367. 17-Apr-1998    Q4
    368. 20-Apr-1998    Q4
    369. 13-Apr-1998    Q4
    370. 08-Apr-1998    Q4
    371. 20-Apr-1998    Q4
    372. 20-Apr-1998    Q4
    373. 20-Apr-1998    Q4
    374. 20-Apr-1998    Q4
    375. 17-Apr-1998    Q4
    376. 08-Apr-1998    Q4
    377. 07-Apr-1998    Q4
    378. 07-Apr-1998    Q4
    379. 01-May-1998    Q4
    380. 21-Apr-1998    Q4
    381. 07-Apr-1998    Q4
    382. 08-Apr-1998    Q4
    383. 08-Apr-1998    Q4
    384. 10-Apr-1998    Q4
    385. 08-Apr-1998    Q4
    386. 13-Apr-1998    Q4
    387. 09-Apr-1998    Q4
    388. 10-Apr-1998    Q4
    389. 10-Apr-1998    Q4
    390. 10-Apr-1998    Q4
    391. 10-Apr-1998    Q4
    392. 10-Apr-1998    Q4
    393. 10-Apr-1998    Q4
    394. 10-Apr-1998    Q4
    395. 08-Apr-1998    Q4
    396. 04-May-1998    Q4
    397. 30-Apr-1998    Q4
    398. 01-May-1998    Q4
    399. 01-May-1998    Q4
    400. 01-May-1998    Q4
    401. 01-May-1998    Q4
    402. 01-May-1998    Q4
    403. 04-May-1998    Q4
    404. 30-Apr-1998    Q4
    405. 04-May-1998    Q4
    406. 28-Apr-1998    Q4
    407. 04-May-1998    Q4
    408. 05-May-1998    Q4
    409. 05-May-1998    Q4
    410. 06-May-1998    Q4
    411. 06-May-1998    Q4
    412. 06-Apr-1998    Q4
    413. 13-Mar-1998    Q4
    414. 04-May-1998    Q4
    415. 24-Apr-1998    Q4
    416. 21-Apr-1998    Q4
    417. 22-Apr-1998    Q4
    418. 22-Apr-1998    Q4
    419. 23-Apr-1998    Q4
    420. 23-Apr-1998    Q4
    421. 23-Apr-1998    Q4
    422. 24-Apr-1998    Q4
    423. 29-Apr-1998    Q4
    424. 24-Apr-1998    Q4
    425. 29-Apr-1998    Q4
    426. 24-Apr-1998    Q4
    427. 24-Apr-1998    Q4
    428. 27-Apr-1998    Q4
    429. 27-Apr-1998    Q4
    430. 27-Apr-1998    Q4
    431. 27-Apr-1998    Q4
    432. 28-Apr-1998    Q4
    433. 21-Apr-1998    Q4
    434. 24-Apr-1998    Q4
    435. 13-Mar-1998    Q4
    436. 11-Mar-1998    Q4
    437. 11-Mar-1998    Q4
    438. 11-Mar-1998    Q4
    439. 12-Mar-1998    Q4
    440. 12-Mar-1998    Q4
    441. 13-Mar-1998    Q4
    442. 13-Mar-1998    Q4
    443. 16-Mar-1998    Q4
    444. 06-May-1998    Q4
    445. 09-Mar-1998    Q4
    446. 16-Mar-1998    Q4
    447. 16-Mar-1998    Q4
    448. 17-Mar-1998    Q4
    449. 18-Mar-1998    Q4
    450. 18-Mar-1998    Q4
    451. 18-Mar-1998    Q4
    452. 18-Mar-1998    Q4
    453. 13-Mar-1998    Q4
    454. 04-Mar-1998    Q4
    455. 02-Mar-1998    Q4
    456. 02-Mar-1998    Q4
    457. 02-Mar-1998    Q4
    458. 03-Mar-1998    Q4
    459. 03-Mar-1998    Q4
    460. 03-Mar-1998    Q4
    461. 04-Mar-1998    Q4
    462. 10-Mar-1998    Q4
    463. 04-Mar-1998    Q4
    464. 09-Mar-1998    Q4
    465. 04-Mar-1998    Q4
    466. 05-Mar-1998    Q4
    467. 05-Mar-1998    Q4
    468. 06-Mar-1998    Q4
    469. 06-Mar-1998    Q4
    470. 06-Mar-1998    Q4
    471. 09-Mar-1998    Q4
    472. 18-Mar-1998    Q4
    473. 04-Mar-1998    Q4
    474. 02-Apr-1998    Q4
    475. 18-Mar-1998    Q4
    476. 27-Mar-1998    Q4
    477. 27-Mar-1998    Q4
    478. 30-Mar-1998    Q4
    479. 30-Mar-1998    Q4
    480. 30-Mar-1998    Q4
    481. 31-Mar-1998    Q4
    482. 27-Mar-1998    Q4
    483. 02-Apr-1998    Q4
    484. 26-Mar-1998    Q4
    485. 02-Apr-1998    Q4
    486. 02-Apr-1998    Q4
    487. 02-Apr-1998    Q4
    488. 03-Apr-1998    Q4
    489. 03-Apr-1998    Q4
    490. 03-Apr-1998    Q4
    491. 03-Apr-1998    Q4
    492. 06-Apr-1998    Q4
    493. 01-Apr-1998    Q4
    494. 23-Mar-1998    Q4
    495. 06-Apr-1998    Q4
    496. 19-Mar-1998    Q4
    497. 19-Mar-1998    Q4
    498. 19-Mar-1998    Q4
    499. 19-Mar-1998    Q4
    500. 20-Mar-1998    Q4
    501. 20-Mar-1998    Q4
    502. 27-Mar-1998    Q4
    503. 20-Mar-1998    Q4
    504. 18-Mar-1998    Q4
    505. 23-Mar-1998    Q4
    506. 23-Mar-1998    Q4
    507. 23-Mar-1998    Q4
    508. 24-Mar-1998    Q4
    509. 24-Mar-1998    Q4
    510. 24-Mar-1998    Q4
    511. 25-Mar-1998    Q4
    512. 26-Mar-1998    Q4
    513. 20-Mar-1998    Q4
    514.  
Mar 31 '09 #2
rcollins
234 100+
So, I think I understand this to the most part, but I see an issue or two. First, Where to I keep the function? do I do this in a module? Also, This seems to be year specific. I would like to be able to use a criteria form for the report, will I have to keep changing dates or is there a way to do this for any year? What about the fact that july through dec 2008 are actually part of fiscal year 2009? it seems that this query would still list these months in the wrong year.
Thanks for all your help, you are very appriciated
Apr 1 '09 #3
ADezii
8,834 Expert 8TB
@rcollins
Where to I keep the function?
In a Standard Code Module
Do I do this in a module?
Previously answered
I would like to be able to use a criteria form for the report, will I have to keep changing dates or is there a way to do this for any year?
It can probably be converted to accept any Year
What about the fact that july through dec 2008 are actually part of fiscal year 2009? it seems that this query would still list these months in the wrong year.
Maybe I'm confused, (fiscally illerate), but isn't July 2008 considered to be Quarter 1 of Fiscal Year 2009, and isn't December 2008 considered to be Quarter 3 of Fiscal Year 2009?

P.S. - Kindly Reply with specifics.
Apr 1 '09 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi. ADezii has shown a query which can with a few adjustments be generalised to work with any year to return a quarter value. It appears to me that what you are really asking for is slightly different - a way to return a year and quarter reference, as you mention being able to show the fiscal year as part of the value.

The function below is an adaptation of one I use to return fiscal year quarters. Like the one ADezii gave you this has to be located in any public code module - one that is shown in the Modules tab within Access. If there are none at present just create a new one and paste the code into the module then save it under any suitable name (not the name of the function, though!).

In the query editor you can use the function to return the quarter reference given the transaction date, as a calculated field set along the lines of

FiscalQuarter: fYearQuarter([your transaction date])

The function returns the quarter year-first to ensure that results can be ordered in ascending or descending order correctly.

Expand|Select|Wrap|Line Numbers
  1. Public Function fYearQuarter(somedate, Optional quarter_start = 3) As String
  2. 'Returns the current financial year quarter for the current financial year
  3. 'in the form yyyy-Qn where yyyy is the financial year and n is the
  4. 'quarter number.
  5. 'Assumes that the financial year starts in quarter 3 of the calendar year
  6. 'which can be varied by changing the default quarter_start value
  7. Dim intQ As Integer, intYear As Integer
  8. If Not IsNull(somedate) Then
  9.     intYear = Year(somedate)
  10.     Select Case quarter_start
  11.     Case 1 To 4
  12.         intQ = CLng(Format(somedate, "q")) - quarter_start + 1
  13.         If intQ <= 0 Then
  14.             intQ = intQ + 4
  15.             intYear = intYear - 1
  16.         End If
  17.         fYearQuarter = intYear & "-Q" & intQ
  18.     Case Else
  19.         fYearQuarter = "invalid start quarter"
  20.     End Select
  21. End If
  22. End Function
Test data (uk date format - dd/mm/yyyy)
Expand|Select|Wrap|Line Numbers
  1. Date    Quarter
  2. 01/07/2008    2008-Q1
  3. 01/08/2008    2008-Q1
  4. 01/09/2008    2008-Q1
  5. 01/10/2008    2008-Q2
  6. 01/11/2008    2008-Q2
  7. 01/12/2008    2008-Q2
  8. 01/01/2009    2008-Q3
  9. 01/02/2009    2008-Q3
  10. 01/03/2009    2008-Q3
  11. 01/04/2009    2008-Q4
  12. 01/05/2009    2008-Q4
  13. 01/06/2009    2008-Q4
  14. 01/07/2009    2009-Q1
  15. 01/08/2009    2009-Q1
  16. 01/09/2009    2009-Q1
  17. 01/10/2009    2009-Q2
  18. 01/11/2009    2009-Q2
  19. 01/12/2009    2009-Q2
  20. 01/01/2010    2009-Q3
  21. 01/02/2010    2009-Q3
  22. 01/03/2010    2009-Q3
  23. 01/04/2010    2009-Q4
  24. 01/05/2010    2009-Q4
  25. 01/06/2010    2009-Q4
  26. 01/07/2010    2010-Q1
  27. 01/08/2010    2010-Q1
  28. 01/09/2010    2010-Q1
  29. 01/10/2010    2010-Q2
  30. 01/11/2010    2010-Q2
  31. 01/12/2010    2010-Q2
-Stewart
Apr 1 '09 #5
Stewart Ross
2,545 Expert Mod 2GB
By the way, I have used a slightly different convention for the year than you mention - in the UK financial years are usually quoted from the year they start, not the year they end, so 1 July 2008 would be Quarter 1 of fiscal year 2008/2009, hence the 2008 you see in the table above.

If you need to have this listed as 2009 the same function can be used - it is just a slight change that is needed, to line 9:

intYear = Year(somedate) + 1

and the test data then becomes
Expand|Select|Wrap|Line Numbers
  1. Date    Quarter
  2. 01/07/2008    2009-Q1
  3. 01/08/2008    2009-Q1
  4. 01/09/2008    2009-Q1
  5. 01/10/2008    2009-Q2
  6. 01/11/2008    2009-Q2
  7. 01/12/2008    2009-Q2
  8. 01/01/2009    2009-Q3
  9. 01/02/2009    2009-Q3
  10. 01/03/2009    2009-Q3
  11. 01/04/2009    2009-Q4
  12. 01/05/2009    2009-Q4
  13. 01/06/2009    2009-Q4
  14. 01/07/2009    2010-Q1
  15. 01/08/2009    2010-Q1
  16. 01/09/2009    2010-Q1
  17. 01/10/2009    2010-Q2
  18. 01/11/2009    2010-Q2
  19. 01/12/2009    2010-Q2
  20. 01/01/2010    2010-Q3
  21. 01/02/2010    2010-Q3
  22. 01/03/2010    2010-Q3
  23. 01/04/2010    2010-Q4
  24. 01/05/2010    2010-Q4
  25. 01/06/2010    2010-Q4
  26. 01/07/2010    2011-Q1
  27. 01/08/2010    2011-Q1
  28. 01/09/2010    2011-Q1
  29. 01/10/2010    2011-Q2
  30. 01/11/2010    2011-Q2
  31. 01/12/2010    2011-Q2
-Stewart
Apr 1 '09 #6
ADezii
8,834 Expert 8TB
@Stewart Ross Inverness
Hello Stewart, always a pleasure to see you. I'm really confused over this whole 'Fiscal Year' definition. If you have time, can you kindly define the 4 Quarters for Fiscal Year 2009, as in:
Expand|Select|Wrap|Line Numbers
  1. Quarter 1 [2009] - 6/1/2008 to 9/30/2008, etc.
Thanks Stewart!
Apr 1 '09 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi ADezii. In the financial community the fiscal year defines a specific tax period for accounting purposes. In the UK the norm for businesses is to have a financial year which runs from 1 April in one year to 31 March in the next year - but there are other patterns similar to the one mentioned by the original poster in post # 1. For example, as a matter of practicality Further Education colleges in Scotland changed their financial year patterns from 1 April year-start to 1 August to do away with the difficulty up to then of matching student activity running from August that straddled two financial years.

As today is 1 April, for many businesses in the UK financial year 2009/10 has just begun (or fiscal year 2010 in terms of the posts above). April, May and June 2009 form quarter 1 of 2009/10, July, August and September 2009 quarter 2, October, November and December 2009 quarter 3, and January, February and March 2010 form quarter 4 of 2009/10. The financial year/fiscal year is the accounting period for which businesses must by law publish audited accounts (at least in the UK). That period (whether referred to as 2009/10 or fiscal year 2010 or whatever else may be conventional) does not change just because the calendar year changes - so January, February and March of 2010 are simply referred to as quarter 4 of 2009/10.

In post 1 the poster refers to a fiscal year starting in quarter 3 (1 July each year), so the first half of the calendar year will belong to the previous fiscal year and the second the next, which is why in the exemplars listed in my final post you see the fiscal year part change in July. The fiscal year quarters for the poster's next fiscal year (2010 if I've correctly picked up the convention) run as follows:

2010 quarter 1: 07/01/2009 - 09/30/2009
2010 quarter 2: 10/01/2009 - 12/31/2009
2010 quarter 3: 01/01/2010 - 03/31/2010
2010 quarter 4: 04/01/2010 - 06/30/2010

Hope my imperfect explanation helps a little.

Regards

Stewart
Apr 1 '09 #8
ADezii
8,834 Expert 8TB
@Stewart Ross Inverness
Explanation was spot on, thanks.
Apr 1 '09 #9
NeoPa
32,556 Expert Mod 16PB
I hope I haven't oversimplified, but wouldn't the following work for you? :
Expand|Select|Wrap|Line Numbers
  1. Format(DateAdd("m",7,Date()),"\qq yyyy")
Replace Date() with any date field you need to work with, and quotes (') for double-quotes (") when used within SQL to be technically correct.
Apr 2 '09 #10
ADezii
8,834 Expert 8TB
@NeoPa
You mean we did all that work for nothing? (LOL).
Apr 2 '09 #11
rcollins
234 100+
@ADezii
I doubt it was for nothing, at least this way I have multiple ways to try. I am having a long weekend from work so I won't be working on this till Monday, but I will let you know how it goes. Thanks for all the feedback, it all helps.
Apr 2 '09 #12
NeoPa
32,556 Expert Mod 16PB
I certainly hope so ADezii :D

But in truth, I think RCollins has the right idea. All ideas are worth exploring.
Apr 2 '09 #13
Stewart Ross
2,545 Expert Mod 2GB
Not quite working, NeoPa (one quarter out in the changeovers), but it's a nice simplification. Applied to the same testdata as above:

Expand|Select|Wrap|Line Numbers
  1. Date    Quarter    Test
  2. 01/07/2008    2009-Q1    q1 2009
  3. 01/08/2008    2009-Q1    q1 2009
  4. 01/09/2008    2009-Q1    q2 2009
  5. 01/10/2008    2009-Q2    q2 2009
  6. 01/11/2008    2009-Q2    q2 2009
  7. 01/12/2008    2009-Q2    q3 2009
  8. 01/01/2009    2009-Q3    q3 2009
  9. 01/02/2009    2009-Q3    q3 2009
  10. 01/03/2009    2009-Q3    q4 2009
  11. 01/04/2009    2009-Q4    q4 2009
  12. 01/05/2009    2009-Q4    q4 2009
  13. 01/06/2009    2009-Q4    q1 2010
  14. 01/07/2009    2010-Q1    q1 2010
  15. 01/08/2009    2010-Q1    q1 2010
  16. 01/09/2009    2010-Q1    q2 2010
  17. 01/10/2009    2010-Q2    q2 2010
  18. 01/11/2009    2010-Q2    q2 2010
  19. 01/12/2009    2010-Q2    q3 2010
  20. 01/01/2010    2010-Q3    q3 2010
  21. 01/02/2010    2010-Q3    q3 2010
  22. 01/03/2010    2010-Q3    q4 2010
  23. 01/04/2010    2010-Q4    q4 2010
  24. 01/05/2010    2010-Q4    q4 2010
  25. 01/06/2010    2010-Q4    q1 2011
  26. 01/07/2010    2011-Q1    q1 2011
  27. 01/08/2010    2011-Q1    q1 2011
  28. 01/09/2010    2011-Q1    q2 2011
  29. 01/10/2010    2011-Q2    q2 2011
  30. 01/11/2010    2011-Q2    q2 2011
  31. 01/12/2010    2011-Q2    q3 2011
-Stewart
Apr 3 '09 #14
Stewart Ross
2,545 Expert Mod 2GB
...but with the following slight tweak
Expand|Select|Wrap|Line Numbers
  1. Format(DateAdd("m", 6, [somedate]), "yyyy-\Qq")
it gives...

Expand|Select|Wrap|Line Numbers
  1. Date    Quarter    Test
  2. 01/07/2008    2009-Q1    2009-Q1
  3. 01/08/2008    2009-Q1    2009-Q1
  4. 01/09/2008    2009-Q1    2009-Q1
  5. 01/10/2008    2009-Q2    2009-Q2
  6. 01/11/2008    2009-Q2    2009-Q2
  7. 01/12/2008    2009-Q2    2009-Q2
  8. 01/01/2009    2009-Q3    2009-Q3
  9. 01/02/2009    2009-Q3    2009-Q3
  10. 01/03/2009    2009-Q3    2009-Q3
  11. 01/04/2009    2009-Q4    2009-Q4
  12. 01/05/2009    2009-Q4    2009-Q4
  13. 01/06/2009    2009-Q4    2009-Q4
  14. 01/07/2009    2010-Q1    2010-Q1
  15. 01/08/2009    2010-Q1    2010-Q1
  16. 01/09/2009    2010-Q1    2010-Q1
  17. 01/10/2009    2010-Q2    2010-Q2
  18. 01/11/2009    2010-Q2    2010-Q2
  19. 01/12/2009    2010-Q2    2010-Q2
  20. 01/01/2010    2010-Q3    2010-Q3
  21. 01/02/2010    2010-Q3    2010-Q3
  22. 01/03/2010    2010-Q3    2010-Q3
  23. 01/04/2010    2010-Q4    2010-Q4
  24. 01/05/2010    2010-Q4    2010-Q4
  25. 01/06/2010    2010-Q4    2010-Q4
  26. 01/07/2010    2011-Q1    2011-Q1
  27. 01/08/2010    2011-Q1    2011-Q1
  28. 01/09/2010    2011-Q1    2011-Q1
  29. 01/10/2010    2011-Q2    2011-Q2
  30. 01/11/2010    2011-Q2    2011-Q2
  31. 01/12/2010    2011-Q2    2011-Q2
-Stewart
Apr 3 '09 #15
NeoPa
32,556 Expert Mod 16PB
@Stewart Ross Inverness
You're right Stewart. I was sloppy with my arithmetic. I must admit that I was focusing my attention on the concept rather than the implementation, and rushed it out.
Apr 3 '09 #16
Stewart Ross
2,545 Expert Mod 2GB
Hi NeoPa. Your solution is a great example of using the built-in facilities (DateAdd and Format in this case) to the full before trying bespoke programming. It is commendably simple! I just wonder why I didn't think of it instead (shakes head...)

Cheers

Stewart
Apr 3 '09 #17
NeoPa
32,556 Expert Mod 16PB
Thanks for that Stewart. I just wish I hadn't spoiled the effect with the nooby arithmetic ;)
Apr 3 '09 #18
ADezii
8,834 Expert 8TB
@Stewart Ross Inverness
Hey Stewart, I always said that NeoPa was commendably simple! I am referring to his programming skills, of course (LOL)!
Apr 3 '09 #19
NeoPa
32,556 Expert Mod 16PB
Very nice ADezii. I actually laughed out loud on that one.
Apr 3 '09 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bp | last post by:
I'm using the System.Globalization.GregorianCalendar class to calculate week numbers. My weeks begin on Saturday and follow the "first four day" rule. GregorianCalendar cal = new...
3
by: charliewest | last post by:
Can someone recommend a fairly easy to use ASP.NET custom calendar control that makes it easy for the user to select the month and year - versus the inherent "paging" that is used in the default...
1
by: ajmera.puneet | last post by:
If I have Calendar Control on Asp.net page and I have a table for Fiscal years on sql server then, How can I check the dates from table to Calendar Control,so that I can format the Calendar...
1
by: rkohon | last post by:
Hello all, I am new to JavaScript and need some ideas, suggestions, or code snippets. I have a form which requires the end user to put in a date for required items. I need javascript function to...
4
by: Twobridge | last post by:
Hi I am trying to perform a search that will return records based on a fiscal year search of the bill_Date. The user gives the year then I want to search based on the fiscal year (July 1 - June...
2
by: Sund via AccessMonster.com | last post by:
I do fair amount of data analysis using access pivot tables and charts. Can any body suggest a method to run the queries based on accounting month and Accounting year.As an example: I want to...
6
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between...
5
by: Lars Eighner | last post by:
Is a calendar tabular data, logically meriting table markup? -- Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner> Countdown: 465 days to go. What do you do when...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
1
by: abhishekbrave | last post by:
The code below is opening a calendar on mouse over in the same window. I need the calendar to be opened in new window. Have to fulfill this requirement urgentely so posting the whole code here. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.