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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Calculate difference between two month

I have  following Columns with in a table

 

 StartMonth         EndMonth                   

 Jan-2017               Mar-2017               

 Nov-2017             Mar-2018              

 

want difference between Startmonth  and endmonth, How can i get following Column?

 

OutPut

3

5

 

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@Anonymous

 

It looks like you can actually use something much simpler like:

 

NewColMonthDiff=
1+ DATEDIFF(DATEVALUE(Table1[StartMonth]), DATEVALUE(Table1[EndMonth]),MONTH)

 

 

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @Anonymous

It would be much easier if you had the dates in another format. How about a new column like this:

 

NewColMonthDiff=
VAR _StartMonthNum=SWITCH( LEFT(Table1[StartMonth],3),
                                 "Jan", 1,
                                 "Feb",2,
                                  ...
                                 "Dec",12)
VAR _EndMonthNum=SWITCH( LEFT(Table1[EndMonth],3),
                                 "Jan", 1,
                                 "Feb",2,
                                  ...
                                 "Dec",12)
VAR _StartYear=RIGHT(Table1[StartMonth],4)
VAR _EndYear  =RIGHT(Table1[EndMonth],4)
RETURN
1+ (_Endyear - _StartYear)*12 + _EndMonthNum - _StartMonthNum

 

where you would have to complete the two SWITCH statements with all the months and their numbers (where I've placed the '...')

 

 

 

    

AlB
Community Champion
Community Champion

@Anonymous

 

It looks like you can actually use something much simpler like:

 

NewColMonthDiff=
1+ DATEDIFF(DATEVALUE(Table1[StartMonth]), DATEVALUE(Table1[EndMonth]),MONTH)

 

 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.