One Task, Six Languages: Calculating the Fiscal Year

When you’re working with financial data, knowing the fiscal year is just as important — if not more — than the calendar year. In this first post of my new series, This Is How We Code It, I’ll show you how to calculate the fiscal year across 6 different languages.
Best part? These are dynamic solutions — no manual input needed. Plug and play your date logic to automate your financial workflows instantly.

Why It Matters
Creating dynamic workflows that don’t require user input is the key to modern efficiency. Whether you’re a developer, analyst, or automation enthusiast, knowing how to apply logic like this across platforms will save you time, reduce errors, and make your work scalable.

Python
from datetime import datetime

input_date = “2021-08-18”
input_date = datetime.strptime(input_date, “%Y-%m-%d”)
fiscal_year = input_date.year + 1 if input_date.month >= 7 else input_date.year

print(f”Fiscal Year: {fiscal_year}”)

Excel
=YEAR(A2) + IF(MONTH(A2) >= 7, 1, 0)

DAX (Power BI / Power Pivot)
= YEAR([Date]) + IF(MONTH([Date]) >= 7, 1, 0)

SQL Server
DECLARE @DATE DATE
SET @DATE = ‘8/13/2024’

SELECT @DATE AS ‘Date’,
YEAR(@DATE) + CASE WHEN MONTH(@DATE) >= 7 THEN 1 ELSE 0 END AS ‘FiscalYear’

VBA
Sub FindFiscalYear()
Dim inputDate As Date
inputDate = #8/13/2024#
fiscalYear = Year(inputDate) + IIf(Month(inputDate) >= 7, 1, 0)
MsgBox “Fiscal Year: ” & fiscalYear
End Sub

Power Query (M)
= Date.Year([Date]) + if Date.Month([Date]) >= 7 then 1 else 0

Final Thought
Automation isn’t just about speed — it’s about reliability, remember, Consistency = Efficiency. Learning to calculate something as fundamental as the fiscal year across multiple platforms is a huge win in efficiency and flexibility.

Want more tips like this?
Check out my book Automate Everything With Python — it’s full of real-world scripts that help you reclaim your time.

News & Events

Jeff Miller

Join Jeff’s journey—whether it’s building automation, writing fiction, or traveling the country.

© 2025 Jeff Miller. All Rights Reserved. Website designed by AdamOure.