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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ddurosier
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.

 

 

 

 

 

 

image.png

 

 

 

2 ACCEPTED SOLUTIONS
dedelman_clng
Community Champion
Community Champion

Hi @ddurosier 

 

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)

 

2020-10-21 13_47_21-scratch4 - Power BI Desktop.png

 

Hope this helps

David

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @ddurosier 

 

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

Table:

a1.png

 

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:

a2.png

 

Best Regards

Allan

 

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @ddurosier 

 

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

Table:

a1.png

 

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:

a2.png

 

Best Regards

Allan

 

 

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

dedelman_clng
Community Champion
Community Champion

Hi @ddurosier 

 

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)

 

2020-10-21 13_47_21-scratch4 - Power BI Desktop.png

 

Hope this helps

David

I will give it a shot ofr that part.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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