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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.