cancel
Showing results for 
Search instead for 
Did you mean: 
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
Microsoft
Microsoft

@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
Microsoft
Microsoft

@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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors