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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Datediff function with decimals

Hi everyone,

 

I am using the function Datediff( ), but the results I am getting are integers, and I need than these ones become decimals.

Example:

Reuslt: 1215

Expected: 1214.7

 

Any suggestions?

Thanks

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

Change date type and format as below:

Capture1.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

7 REPLIES 7
ninhtran1301
Regular Visitor

The way around it that worked for me is to make the unit seconds in datediff function then divide by 3600 if you want it in hour then it will be more accurate. Depends on the datetime format you're trying to subtract.

For example in my case I want to get the hour difference in Start and stop time below:

 

calculate(DATEDIFF(min('Scrub Tool'[START_TIME]),max('Scrub Tool'[STOP_TIME]),SECOND),filteredrows)/3600

Btw, this is in DAX. 

i-technology
New Member

How about this DAX formula

var nbrMonths = YEARFRAC(startDate, endDate) * 12
var result    = DIVIDE(something, nbrMonths, 0)

I was having an issue where I was using the DateDiff function in DAX and it was producing a rounded down number of months 

 

Ie, if a transacted occurred on the 1st of Jan, 2023 and today is the 7th of July, 2023 the result returned for a DATEDIFF between the values was 6 months even though, technically, its 6 and a bit months. 

 

For my logic, 6 and a bit months needed to be rounded up to 7 months

 

I tried rounding functions on the DATEDIFF function but the realized it wouldn't work as a DATEDIFF doesn't produce a decimal

 

Using your function produced the decimal and allowed the round function to work 

 

This is my end expression for reference:

Months Since Last Transacted = 
VAR LastTransacted = 
IF(
    ISBLANK(PTStock_Data[LAST_DEM_DATE]) && 
	ISBLANK(PTStock_Data[Last_Invoiced_Datetime]), 
    PTStock_Data[CREATION_DATE],
    IF(
        ISBLANK(PTStock_Data[LAST_DEM_DATE]) && 
		NOT(ISBLANK(PTStock_Data[Last_Invoiced_Datetime])),
        PTStock_Data[Last_Invoiced_Datetime], 
        PTStock_Data[LAST_DEM_DATE]
    )    
)
VAR MonthsSinceTransacted = 
ROUNDUP( YEARFRAC( LastTransacted, TODAY() ) *12, 0 )

RETURN
MonthsSinceTransacted
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Is this problem sloved? 
If it is sloved, could you kindly accept it as a solution to close this case and help the other members find it more quickly?
If not, please feel free to let me know.
 
Best Regards
Maggie
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

Change date type and format as below:

Capture1.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

What are you taking as date diff? Assume you are taking Day , Then take in hours and divide by 24

 

Diff = datediff(date1,date2,day)

Diff = datediff(date1,date2,Hour)/24

Same is true with other types

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Super User
Super User

Can you just use subtraction?

 

( Date1 - Date/Time ) * 1.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.