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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Alisea_MI
Resolver II
Resolver II

Help on DAX Turnaround in Hours

Hi,

I would appreciate help on a DAX formula, that should calculate the number of hours between the sample received date and time and sample completed date and time. 

In the model I have separate Date table for the Dates and Time table for the hours, each of them has active and passive relationships with  some date columns from the fact table.
Community model.jpg

The formula I am working on is below together with the error message.

Wold be grateful for any tips on how to make it work.

community dax.jpg


1 ACCEPTED SOLUTION

Hi, @Alisea_MI 

 

This formula you tested works.

vzhangti_0-1697530219051.png

You can also try the following methods.

Measure 2 = 
Var _date1=DATEVALUE(SELECTEDVALUE(Labvantage[SampleReceivedDate])&" "&SELECTEDVALUE(Labvantage[SampleReceivedTime]))
Var _date2=DATEVALUE(SELECTEDVALUE(Labvantage[SampleCompletedDate])&" "&SELECTEDVALUE(Labvantage[SampleCompletedTime]))
Return
DATEDIFF(_date1,_date2,HOUR)

vzhangti_1-1697530273241.png

DATEVALUE function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Community Support Team _Charlotte

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
Alisea_MI
Resolver II
Resolver II

Thanx, @amitchandak ! 
Unfortunately, I get this error: "the expression specified in the query is not a valid table expression".

I have also tested this: 

VAR _datediff = DATEDIFF(MAX(Labvantage[SampleReceivedDate]), MAX(Labvantage[SampleCompletedDate]), HOUR)
VAR _samplecompletedTime = MAXX(ALL(Labvantage), Labvantage[SampleCompletedTime]) * 24
VAR _samplereceivedTime = MAXX(ALL(Labvantage), Labvantage[SampleReceivedTime]) * 24
VAR _datetimedif = _datediff + _samplecompletedTime - _samplereceivedTime

RETURN
_DATETIMEDIF


Can it be so that it's not possible to create a measure on it?

Hi, @Alisea_MI 

 

This formula you tested works.

vzhangti_0-1697530219051.png

You can also try the following methods.

Measure 2 = 
Var _date1=DATEVALUE(SELECTEDVALUE(Labvantage[SampleReceivedDate])&" "&SELECTEDVALUE(Labvantage[SampleReceivedTime]))
Var _date2=DATEVALUE(SELECTEDVALUE(Labvantage[SampleCompletedDate])&" "&SELECTEDVALUE(Labvantage[SampleCompletedTime]))
Return
DATEDIFF(_date1,_date2,HOUR)

vzhangti_1-1697530273241.png

DATEVALUE function (DAX) - DAX | Microsoft Learn

 

Best Regards,

Community Support Team _Charlotte

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

amitchandak
Super User
Super User

@Alisea_MI , if they are from same table better to create a column

 

Datediff([StartDate]+[Start Time], [end Date]+[end Time], second)

 

or a measure

 

sumx(Table, Datediff([StartDate]+[Start Time], [end Date]+[end Time], second))

 

You can use new measure formatting to display it in time format

 

Power BI Dynamic Format Strings for Measures| Format without converting to text: https://youtu.be/qHALucET7N8

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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