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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.