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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
martinhyy
Frequent Visitor

How to calculate the duration in M or other language

Hi community,

 

This is my first post. I'm just wondering how to use any language to track the time that is used to query the data.

 

Concretely, I've got a query purely in MDX, when I choose a certain date range and load it directly to Power BI, it takes about 7mins to finish the loading (by looking at the clock). However I would like to know the exact time that is spent on the loading process.

 

I imagine there should be some kind of code

 

let 
   
    start_Time = DateTime.LocalNow()
   
    source = /*my MDX code here*/

    duration = DataTime.LocalNow() - start_Time

in
   
    duration

The code above always gives me a duration that is really close to 0 which probably means it didn't run the source part? Any ideas how I can make this correction?

 

Thanks

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee


Measuring execution time in Power Query is not easy, especially because of the answer to your last question: no, execution order is not guaranteed from top to bottom. Instead, Power Query uses lazy evaluation, i.e. code won't be evaluated until it is actually required.

You may best be helped by this blog from Chris Webb in which he explains how to use Diagnostics.Trace to measure execution time.


 

See the reply from @MarcelBeug in Power Query - log start and end time of running a query

View solution in original post

1 REPLY 1
Eric_Zhang
Employee
Employee


Measuring execution time in Power Query is not easy, especially because of the answer to your last question: no, execution order is not guaranteed from top to bottom. Instead, Power Query uses lazy evaluation, i.e. code won't be evaluated until it is actually required.

You may best be helped by this blog from Chris Webb in which he explains how to use Diagnostics.Trace to measure execution time.


 

See the reply from @MarcelBeug in Power Query - log start and end time of running a query

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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