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! Request now

Reply
Anonymous
Not applicable

Calculate number of months from 02 different years

Hi,

Im calculating number of months in two different years.That means if i select date filter from 2020 jan 1st to todate i need to show 2020 has 12 months and 2021 has 02 months todate from january.i want to show 02 cards seperately to show months.is there a way to do this? I tries Datediff. But it shows months count form 2020 to todate. Can someone help me to get this?

Thanks

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

Will you only select dates in two adjacent years? Will you always filter a data range until today?

 

If you only filter dates in last year and this year, you can create below measures:

  • Measure A = DATEDIFF(MIN('Date'[Date]),DATE(2020,12,31),MONTH)+1
  • Measure B = DATEDIFF(DATE(YEAR(TODAY()),1,1),TODAY(),MONTH)+1

If the last year will not always be 2020, you can modify Measure A like below:

  • Measure A2 = DATEDIFF(MIN('Date'[Date]),DATE(YEAR(TODAY())-1,12,31),MONTH)+1

If you will not always use today as the last date of your date selection, you can use below measures:

  • Measure A3 = DATEDIFF(MIN('Date'[Date]),DATE(YEAR(MAX('Date'[Date]))-1,12,31),MONTH)+1
  • Measure B3 = DATEDIFF(DATE(YEAR(MAX('Date'[Date])),1,1),MAX('Date'[Date]),MONTH)+1

All of above measures don't deal with the conditions if you select dates period in more than 2 years or in only a single year. Let me know if you have more conditions and I can modify the measures accordingly.

 

Additionally, I believe we can use simpler measures like below.

  • Measure A4 = 13-MONTH(MIN('Date'[Date]))
  • Measure B4 = MONTH(TODAY())

 

Regards,

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

@AnonymousDoes my reply solve your problem? If yes, kindly accept it as the solution. Otherwise, please provide more details about your problem so that we can work on it further. Thanks.

v-jingzhang
Community Support
Community Support

Hi @Anonymous 

Will you only select dates in two adjacent years? Will you always filter a data range until today?

 

If you only filter dates in last year and this year, you can create below measures:

  • Measure A = DATEDIFF(MIN('Date'[Date]),DATE(2020,12,31),MONTH)+1
  • Measure B = DATEDIFF(DATE(YEAR(TODAY()),1,1),TODAY(),MONTH)+1

If the last year will not always be 2020, you can modify Measure A like below:

  • Measure A2 = DATEDIFF(MIN('Date'[Date]),DATE(YEAR(TODAY())-1,12,31),MONTH)+1

If you will not always use today as the last date of your date selection, you can use below measures:

  • Measure A3 = DATEDIFF(MIN('Date'[Date]),DATE(YEAR(MAX('Date'[Date]))-1,12,31),MONTH)+1
  • Measure B3 = DATEDIFF(DATE(YEAR(MAX('Date'[Date])),1,1),MAX('Date'[Date]),MONTH)+1

All of above measures don't deal with the conditions if you select dates period in more than 2 years or in only a single year. Let me know if you have more conditions and I can modify the measures accordingly.

 

Additionally, I believe we can use simpler measures like below.

  • Measure A4 = 13-MONTH(MIN('Date'[Date]))
  • Measure B4 = MONTH(TODAY())

 

Regards,

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

amitchandak
Super User
Super User

@Anonymous , Measures like these

 

new measure =
if(year(Selectvalue(Date[Date])) < year(Today), datediff(Selectvalue(Date[Date]),date(year(Selectvalue(Date[Date]),12,31)), month),0)

new measure 2
datediff(today(), date(year(today()),1,1),month)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak these measures are not working at all. Thanks for the answers

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors