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
Kristofferaabo
Helper IV
Helper IV

How to calculate days/months between to date columns

Hi, I have to columns of dates and with the new aggreagted option in the Jan 17 version of powerBI iI was hoping to see some 'levels' in the dates. Especially the time between the First date in column X and the last date in column Y.

 

Im however struggeling to calcualte the days (months preferebly) between the two columns below ('earlist FPI and Latest LPI'). I have tried the datediff but it returns errors..

 

Any ideas?

 

powerBI question.png

 

 

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@Kristofferaabo

 

Hello, try with these measures

 

Diff in Days=
DATEDIFF ( FIRSTDATE ( Table2[Date] ), LASTDATE ( Table2[Date] ), DAY )
Diff in Months=
DATEDIFF ( FIRSTDATE ( Table2[Date] ), LASTDATE ( Table2[Date] ),MONTH )



Lima - Peru

View solution in original post

v-sihou-msft
Employee
Employee

@Kristofferaabo

 

What does the error message say?

 

Make sure those two columns are data type, it supposes to work when using DATEDIFF() function.

 

4.PNG

 

55.PNG

 

Regards,

View solution in original post

4 REPLIES 4
v-sihou-msft
Employee
Employee

@Kristofferaabo

 

What does the error message say?

 

Make sure those two columns are data type, it supposes to work when using DATEDIFF() function.

 

4.PNG

 

55.PNG

 

Regards,

Vvelarde
Community Champion
Community Champion

@Kristofferaabo

 

Hello, try with these measures

 

Diff in Days=
DATEDIFF ( FIRSTDATE ( Table2[Date] ), LASTDATE ( Table2[Date] ), DAY )
Diff in Months=
DATEDIFF ( FIRSTDATE ( Table2[Date] ), LASTDATE ( Table2[Date] ),MONTH )



Lima - Peru

Perfect! Thanks a lot, it works! 🙂

K

 

 

Another poblem I have is that it will not work if I have some empty cells in the columns.

Can I somehow account not to calculate with where there is blank cells? 

 

Kristoffer

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.