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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
KatyJ44
New Member

calculating days between 2 dates on direct query

Hello everyone, we've recelently been able to connect Maximo into Power Bi through Azure databricks. 

i'm using this data to track maintenance legal compliance and i want to look at the days between 2 dates, Target Complete Date and Today, on my other Power BIs which are just ran from Excel sheets and sharepoints i can use all DAX functions and do this easily, but on this one i can not, i can see through research that DAX does not work well with Direct Queries, but i really want this to display on my dashboard. 

This is what i want to calculate,

 

Days until PM Due  = NOW() - '`hive_metastore` `maxmp76_raw` `workorder`'[TARGCOMPDATE] 
 
if anyone can help i would be greatful, Thank you!

 

4 REPLIES 4
v-jialongy-msft
Community Support
Community Support

Hi @KatyJ44 

 

You can try the following formula in Direct query model

Date diff = 
DATEDIFF(
    'Table'[Date],
    TODAY(),
    DAY
)

 

I connected a table using the direct query mode and tested it to be able to implement your needs.

vjialongymsft_0-1708411185401.png

 

 

 

 

Best Regards,

Jayleny

 

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

Greg_Deckler
Super User
Super User

@KatyJ44 Try:

Days until PM Due  = ( NOW() - '`hive_metastore` `maxmp76_raw` `workorder`'[TARGCOMPDATE] ) * 1.

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, unfortunalety it didnt work 😞

just out of curiosity what would the *1 at the end of the calculation do?

i'm self taught on PBI so i may have something formatted wrong in the background and DAX and DirectQuery are relatively new to me!

 

@KatyJ44 Let's back up, are you trying to do this in a measure? If so, then you probably need something like this:

Days until PM Due  = ( NOW() - MAX('`hive_metastore` `maxmp76_raw` `workorder`'[TARGCOMPDATE]) ) * 1.

In DAX, dates are just decimal numbers. The integer portion is the number of days since December 30th, 1899 while the decimal portion is fractions of a day 1/24/60/60. So you can just subtract two dates and multiply by 1 in order to ensure you get back a number instead of a date.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.