Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi Experts , How can I split years between two dates using Dax or Power Query
Start Date | End Date | Output |
01-01-2021 | 01-01-2023 | 2021, 2022, 2023 |
Using Power Query :
let
SplitYears = (StartDate, EndDate) =>
let
StartYear = Date.Year(StartDate),
EndYear = Date.Year(EndDate),
ListYears = {StartYear..EndYear},
Result = Table.FromList(ListYears, Splitter.SplitByNothing())
in
Result
in
SplitYears
Now you can use this function in your main query :
SplitYears([Start Date],[End Date])
Using DAX :
You can create a calculated table with the following DAX formula:
YearTable =
ADDCOLUMNS(
CALENDAR(
YEAR(MIN(Table[Start Date])),
YEAR(MAX(Table[End Date]))
),
"Year", YEAR([Date])
)
Then create a calculated column in your main table that concatenates the years for each row. You could use the CONCATENATEX function to do this :
YearList =
CALCULATE(
CONCATENATEX(
YearTable,
YearTable[Year],
", "
),
YearTable[Year] >= YEAR(Table[Start Date]),
YearTable[Year] <= YEAR(Table[End Date])
)
User | Count |
---|---|
98 | |
76 | |
76 | |
49 | |
27 |