Forum Discussion
Anonymous
3 years agoNot applicable
Unable to calculate the difference between two dates in a Direct Query model
Hi, I'm having trouble calculating the difference between two date fields in a Direct Query model, I'm looking for the number of hours between them. I've tried three different calculated column form...
DataInsights
Super User
3 years agoAnonymous,
What database are you using? I got the measure below to work in a DirectQuery table that uses SQL Server:
Duration Hours = ( MAX ( FactTable[EndDateTime] ) - MAX ( FactTable[StartDateTime] ) ) * 24
Anonymous
3 years agoNot applicable
Hi DataInsights, sorry I forgot to mention that - it's a PostgreSQL database. Thanks for the suggestion, unfortunately
Duration Hours = ( MAX ( FactTable[EndDateTime] ) - MAX ( FactTable[StartDateTime] ) ) * 24
Also doesn't error when creating it, but then says 'Can't display the visual' when I try and put in a table.
- DataInsights3 years ago
Super User
Anonymous,
Have you tried using custom SQL in the PostgreSQL connector?
- Anonymous3 years agoNot applicable
Hi @DataInsights, no I haven't, how do I use custom SQL in the PostgreSQL connector?
- DataInsights3 years ago
Super User
Anonymous,
In Advanced options, enter custom SQL in the "SQL statement" box: