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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
android1
Post Patron
Post Patron

Time difference in hours

Hi,

 

I'm trying to calculate the diiference in hours between two date/time columns. When I use DateDiff I am not able to use the two columns below.

 

Time Difference.jpg

13 REPLIES 13
Anonymous
Not applicable

Also can use a measure, i feel little faster loading time with this 


TimeDiff = CONVERT(SELECTEDVALUE(Table[Date1],0)-SELECTEDVALUE(Table[Date2],0),DATETIME)


and then change the format to time hh:mm:ss
Cheers

Vvelarde
Community Champion
Community Champion

DATEDIFF(TablaHoras[TimeFrom];TablaHoras[TimeTo];HOUR)




Lima - Peru

Thanks for both answers. I'm getting the below error for both;

 

Time.jpg

DateDiff_Big...In PowerBI this function doesnt work.

 

Your Measure should be look like this:

 

MeasureName=DateDiff(xxxxxx,xxxxxx,Hour)




Lima - Peru

I'm confused. When I type DateDiff( I don't get the TimeFrom or TimeTo columns for selection in the measure.

If I use a calculated column I do but get the above error.

Hi @android1,

 

In your scenario, please take a look at @Sean's first reply. You need to create a calculated column instead of measure by clicking "New Column" button. As you mentioned the error occurs when you create a calculated column, would you please share a screenshot about the DAX expression for this column? And which visual do you use to display this calculated column values?

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Qiuyun_Yu,

I am using a Table visualisation. Here is the custom column  ->DateDiff.png

 

 

 

Hi @android1,

 

From the image, the custom column DAX expression is correct. And I havn't seen the table visual displays the error you mentioned. Would you mind sharing the .pbix file for us to analyze closely?

 

Best regrdas,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Sean
Community Champion
Community Champion

@android1 You have to create a COLUMN - NOT a Measure!

 

Look at the picture in my post above - you can't do this as a Measure - that's why the columns are not showing up when you type!

 

click New Column - then you'll see the columns will show up after you type DATEDIFF

 

@android1 the error above is datediffBig function change to datediff




Lima - Peru
Sean
Community Champion
Community Champion

@android1 You are creating a Column right? And the function is DATEDIFF

 

Datediff.png

Sean
Community Champion
Community Champion

@android1 So you've verified both columns are date/time.

 

Then maybe you have some start (FROM) times that are after the corresponding end (TO) times.

 

See if this works - but don't forget that this means some of your data is not in the right order...

 

Hours = SWITCH( 
            TRUE(), 
               'Table'[TimeFrom]<'Table'[TimeTo], DATEDIFF('Table'[TimeFrom], 'Table'[TimeTo], HOUR),
               'Table'[TimeFrom]>'Table'[TimeTo], DATEDIFF('Table'[TimeTo], 'Table'[TimeFrom], HOUR),
               0 )

Dear Sean i tried this method and it worked fine i want to see it in minutes how can i do it ?????

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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