Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
DataVitalizer
Solution Sage
Solution Sage

Generate list of years between two dates

Hi Community,

From this table structure

CategoryDate1Date2
CAT-A25/06/202212/07/2026
CAT-B2/1/202315/10/2025

 

I want to add a new column (Years) that contains a serie of all years between the date1 and date2

CategoryDate1Date2Years
CAT-A25/06/202112/07/20262021,2022,2023,2024,2025,2026
CAT-B2/1/202315/10/20252022,2023,2024,2025

 

Any suggestions?

Thank you in advance

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

I think the example is not accurate but I get the idea.

In Power Query, add a custom column:

{ Date.Year([Date1])..Date.Year([Date2])}

This will create a list which you can expand from the interface (choose Extract Values then a comma for the separator)

 

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

fnd try this

Years = 
VAR _Date = GENERATESERIES(YEAR([Date1]),YEAR([Date2]) ) 
RETURN
    CONCATENATEX ( _Date, [Value], ",", [Value], ASC )

Screen Capture #1305.png

Ahmedx
Super User
Super User

in powe query

 

Text.Combine(
List.Transform(
List.Generate( ()=> [Date1],
 (x) => x<= [Date2],
 (x)=> Date.AddYears( x,1)),
          (y)=> Text.From (Date.Year(y))),", ")
-------------------------------
or 
Text.Combine( List.Transform(
{Date.Year([Date1])..Date.Year([Date2])},
    (y)=> Text.From(y)),", ")

 

 

Screen Capture #1304.pngScreen Capture #1306.png

HotChilli
Super User
Super User

I think the example is not accurate but I get the idea.

In Power Query, add a custom column:

{ Date.Year([Date1])..Date.Year([Date2])}

This will create a list which you can expand from the interface (choose Extract Values then a comma for the separator)

 

Ahmedx
Super User
Super User

pls try this

Years = 
VAR _Date =
    DISTINCT (
        SELECTCOLUMNS (
            ADDCOLUMNS ( CALENDAR ( [Date1], [Date2] ), "Year", YEAR ( [Date] ) ),
            "@YEAR", [Year]
        )
    )
RETURN
    CONCATENATEX ( _Date, [@YEAR], ",", [@YEAR], ASC )

Screen Capture #1302.png

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors