cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Frequent Visitor

## How to find difference between two dates in hours.

Hi
I am new to Dax. I want find difference between two dates in hours. I tried by using DATEDIFF function but it is excluding minutes

I want result like this

Is there another way to solve this probem.
@amitchandak

1 ACCEPTED SOLUTION
Memorable Member

Hi,

You need to calc the Hour and Minutes separately, then add the particular text Hr and Min to the text one.

use the below code for your measure :

DateDiffInHour = CONCATENATE(
CONCATENATE(
DATEDIFF( values(Sheet244[In Time]), values(Sheet244[Out Time]),hour)
, " hr ")
,
CONCATENATE(  mod( DATEDIFF( values(Sheet244[In Time]), values(Sheet244[Out Time]), minute), 60)," min")
)

Mahyartf
3 REPLIES 3
Frequent Visitor

Hi @MahyarTF  I have already tried by using datediff I want ans like this :

Memorable Member

Hi,

You need to calc the Hour and Minutes separately, then add the particular text Hr and Min to the text one.

use the below code for your measure :

DateDiffInHour = CONCATENATE(
CONCATENATE(
DATEDIFF( values(Sheet244[In Time]), values(Sheet244[Out Time]),hour)
, " hr ")
,
CONCATENATE(  mod( DATEDIFF( values(Sheet244[In Time]), values(Sheet244[Out Time]), minute), 60)," min")
)

Mahyartf
Memorable Member

Hi

did you use the Interval in your dax :

DateDiffInHour = DATEDIFF( values(Sheet244[In Time]), values(Sheet244[Out Time]),HOUR)

Appreciate your Kudos and please mark my response as a solution if it helps you

Mahyartf

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors