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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
lisamb1
Regular Visitor

How to Get Time Difference Between Two Date/TIme Columns by Creating a New Column

Hello Community,

 

I have a table that has a "Created" date/time field and a "LastUpdated" date/time field. I would like to create a new column that will display the amunt of time difference between the 2 columns. When the new column is created using the following DAX the column displays the same result for every row and the values are not unique.

 

CustomDurationAverage =

       VAR total_second = 

       AVERAGEX(

                'tablename'

                DATEDIFF('tablename' [Created], 'tablename' [LastUpdated], SECOND)

)

 

      VAR NEWDay = INT(total_second/(24*60*60))

      VAR NEWHours = MOD(INT(total_second/(60*60)),24)

      VAR NEWMin = MOD(INT(total_second/60),60)

      VAR NEWSec = MOD(total_second,60)

 

      RETURN NEWDay &" Day "& NEWHours &" Hour "& NEWMin &" Minute "& NewSec & " Second"

 

This is what I am receiving for all of the results in the new CustomDurationAverage column

0 Day 1 hour 32 Minute 58.9946632653064 Second

 

Is there another way of creating a new column with the results or what am I missing in the DAX code above? Is there a way that I can display the results in the new CustomDurationAverage column as 00:00:00:00 instead of as a text field with each vaule broken out?

 

Thank you all for your help!

 

 

1 ACCEPTED SOLUTION
HashamNiaz
Solution Sage
Solution Sage

Hi !

you can use the following DAX to create a new column;

 

CustomDurationAverage = 
    VAR total_second = 
        DATEDIFF('tablename'[Created], 'tablename'[LastUpdated], SECOND)
    VAR NEWDay = INT(total_second/(24*60*60))
    VAR NEWHours = MOD(INT(total_second/(60*60)),24)
    VAR NEWMin = MOD(INT(total_second/60),60)
    VAR NEWSec = MOD(total_second,60)
RETURN 
    NEWDay &" Day "& NEWHours &" Hour "& NEWMin &" Minute "& NewSec & " Second"

 

Regards,

View solution in original post

3 REPLIES 3
HashamNiaz
Solution Sage
Solution Sage

Hi !

you can use the following DAX to create a new column;

 

CustomDurationAverage = 
    VAR total_second = 
        DATEDIFF('tablename'[Created], 'tablename'[LastUpdated], SECOND)
    VAR NEWDay = INT(total_second/(24*60*60))
    VAR NEWHours = MOD(INT(total_second/(60*60)),24)
    VAR NEWMin = MOD(INT(total_second/60),60)
    VAR NEWSec = MOD(total_second,60)
RETURN 
    NEWDay &" Day "& NEWHours &" Hour "& NEWMin &" Minute "& NewSec & " Second"

 

Regards,

HashamNiaz, thank you this resolved the issue! Is there a way to dispaly the CustomDurationAverage as 00:00:00:00 instead of as 0 Day 0 Hour 59 Minute 40 Second?

 

Thank you again for all of your assistance!

I figured it out. Thanks!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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