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
Anonymous
Not applicable

Incorrect duration of days using Duration in power bi query

Hi All,

 

I am facing this issue where I am using "Duration. Days" to calculate aging of tickets so my tickets data has an attribute "sys_created_on"  and the days are calculated in the power query using the local now function.

 

#"Added Custom" = Table.AddColumn(#"Expanded DimSupportGroup_GlobalSupport", "Ageing", each Duration.Days(DateTime.LocalNow()-[sys_created_on]))

 

above is the statement in m query calculating duration in days but the issue is the duration is not accurate for eg. for 7/30/2020 the duration should be one day but I am getting 0 in the table.

 

Is there anything I am missing here. Or since I am using the Local now the days are calculated based on my system settings. If so how can make this calculation independent of local time?

 

 

 

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @Anonymous , 

Yes, you could refer to @MattAllington 's reply, so if you want to get date difference and ignore time in date, I think you could try below M code

= Table.AddColumn(#"Added Custom1", "Custom.2", each DateTime.Date(DateTime.LocalNow())-DateTime.Date([Column1]))

 

Best Regards,
Zoe Zhi

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

You cannot debug Problems if you can't see the interim results. Add dateTime.localnow() to a column so you can see it. Work out the difference manually. Duration.days extracts the full days portion. 23:59:59 = 0. 24:00:00 = 1



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
amitchandak
Super User
Super User

@Anonymous , is it consistent?  Typically all date function does not consider < 24 hours a day. Like in datediff diff between 30 Jul -30jul i 0 in terms of the day. This could be 1 day present in HR. Typically we end up adding +1 in such cases

Anonymous
Not applicable

Thanks maybe I understood the cause is related to time along with dates and yes for some values it's calculating the correct results

dax
Community Support
Community Support

Hi @Anonymous , 

Yes, you could refer to @MattAllington 's reply, so if you want to get date difference and ignore time in date, I think you could try below M code

= Table.AddColumn(#"Added Custom1", "Custom.2", each DateTime.Date(DateTime.LocalNow())-DateTime.Date([Column1]))

 

Best Regards,
Zoe Zhi

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

 

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.