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

## Datediff Calculation

Looking for some assistance for a correct Output.

Scenario: I have TableA that shows the time (datestringProd) column of each change made for a product# (ProductColumn).  One Product number can have multiple changes for example Prod# 198763 have to different change that were made and same for Prod# 198741. I'm Trying to get the duration for each Prod# output to Measure2 Visual.

Should Look Like this:   Prod# 198763 duration from DateStringProd (11:29pm - 8:21pm) = 3hr 8min

Prod#: 198741 duration from DateStringProd (4:25pm - 2:46pm) = 1hr 39min

Measure2 output = (3h8m + 1h39m) = 4 hr 48mins

Instead it Looks Like this::::  Measure2:::: Prod#: 198741  (2:46pm) + Prod# 198763 (11:29pm) = 8hr 43 mins

If I can get the ouput of Measure2 to even show it in the format 4hr 48mins that'll be fantasy. Please help, i'm still doing some research but been stuck on this for a while. thank you so much team.

2 ACCEPTED SOLUTIONS
Community Champion

Try something like this

``````Measure2 =
SUMX ( VALUES ( Durations[Prod] ), [Measure1] )

Measure2_Formatted =
VAR __HH =
FLOOR ( [Measure2], 1 )
VAR __MM =
ROUND ( ( [Measure2] - __HH ) * 60, 0 )
RETURN
__HH & ":" & __MM
``````

(I don't remember if there's a function that just takes the decimal part of a number in DAX, hence the complex formula)

Hope this helps

David

Community Support

Hi, @ddurosier

Based on your description, I created data to reporduce your scenario. The pbix file is attached in the end.

Table:

You may create a measure as below.

``````Result =
var tab =
SUMMARIZE(
'Table',
'Table'[Prod],
"Re",
DATEDIFF(
MIN('Table'[DateStringProd]),
MAX('Table'[DateStringProd]),
MINUTE
)
)
var result =
SUMX(
tab,
[Re]
)
return
INT(DIVIDE(result,60))&"hr "&MOD(result,60)&"min"``````

Result:

Best Regards

Allan

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

3 REPLIES 3
Community Support

Hi, @ddurosier

Based on your description, I created data to reporduce your scenario. The pbix file is attached in the end.

Table:

You may create a measure as below.

``````Result =
var tab =
SUMMARIZE(
'Table',
'Table'[Prod],
"Re",
DATEDIFF(
MIN('Table'[DateStringProd]),
MAX('Table'[DateStringProd]),
MINUTE
)
)
var result =
SUMX(
tab,
[Re]
)
return
INT(DIVIDE(result,60))&"hr "&MOD(result,60)&"min"``````

Result:

Best Regards

Allan

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

Community Champion

Try something like this

``````Measure2 =
SUMX ( VALUES ( Durations[Prod] ), [Measure1] )

Measure2_Formatted =
VAR __HH =
FLOOR ( [Measure2], 1 )
VAR __MM =
ROUND ( ( [Measure2] - __HH ) * 60, 0 )
RETURN
__HH & ":" & __MM
``````

(I don't remember if there's a function that just takes the decimal part of a number in DAX, hence the complex formula)

Hope this helps

David

Frequent Visitor

I will give it a shot ofr that part.

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