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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sgupta22
Helper II
Helper II

DATESBETWEEN with yearly intervals

Hi everyone!

 

I am trying to create a table using the DatesBetween function where I want the table to have yearly increments. I am using the below formula which gives all the dates between the two dates but I am unable to figure out how to get yearly increments:

 

Model Dates = DATESBETWEEN('Calendar'[Date], [Model start date], [Model end date])

 

 

Thank you for your help!

 

Cheers

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @sgupta22 

Here are the steps you can refer to :

(1)This is my test data:

Table = CALENDAR( DATE(1988,1,1) , DATE(2023,12,31))
(2)We can create a table:
 
Table 2 =
var _table=GENERATESERIES( YEAR(MIN('Table'[Date])),YEAR(MAX('Table'[Date])),1)
return
SELECTCOLUMNS(ADDCOLUMNS(_table,"Date",DATE([Value],1,1)-1) ,"Date",[Date])
 
(3)Then we can meet your need , the result is as follows:
vyueyunzhmsft_0-1664784521559.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

4 REPLIES 4
v-yueyunzh-msft
Community Support
Community Support

Hi , @sgupta22 

Here are the steps you can refer to :

(1)This is my test data:

Table = CALENDAR( DATE(1988,1,1) , DATE(2023,12,31))
(2)We can create a table:
 
Table 2 =
var _table=GENERATESERIES( YEAR(MIN('Table'[Date])),YEAR(MAX('Table'[Date])),1)
return
SELECTCOLUMNS(ADDCOLUMNS(_table,"Date",DATE([Value],1,1)-1) ,"Date",[Date])
 
(3)Then we can meet your need , the result is as follows:
vyueyunzhmsft_0-1664784521559.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Greg_Deckler
Super User
Super User

@sgupta22 What do you mean "year increments" ?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I mean rather than getting a table which has daily dates between the two dates, I want it to be something like this:

31-Dec-2010

31-Dec-2011

31-Dec-2012

31-Dec-2013

31-Dec-2014

and so on...

 

Cheers

@sgupta22 Try:

Model Dates = 
DISTINCT
  SELECTCOLUMNS(
    SUMMARIZE(
      DATESBETWEEN('Calendar'[Date], [Model start date], [Model end date]),
      'Calendar'[Year],
      '__Date',MAX('Calendar'[Date])
    ),
    "Date",[__Date]
  )
)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors