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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Asil098
New Member

calculating time

Hi Everyone,

I am trying to calculate the time difference between the end_date and the start_date, and I want the result in minutes. In some observations, start_date> end_date, and I have used the if condition, but I am still getting the error, and I already calculated the time difference column in the data model by using the datediff DAX function, but the calculated column is not showing in Power Query.

Please help me.

5 REPLIES 5
v-tejrama
Community Support
Community Support

Hi @Asil098,

 

Thanks for sharing your query in detail.

 

I have tested and reproduced your scenario in Power BI, including cases where the start_date is greater than the end_date, and I’m happy to confirm that I got the expected output exactly as per your requirement.


I used a DAX calculated column to compute the time difference in minutes, and it successfully handles both normal and reverse date situations. The output displays positive, negative, or zero values depending on the date order, matching your requirement perfectly.

For your convenience, I have also attached a sample .pbix file showing the complete setup with data, DAX logic, and a table visual, so you can easily review, test, or modify it as needed.


Please find the attached .pbix file for your reference.

 

If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it.


Best Regards,
Tejaswi.
Community Support

 

 

Hi @Asil098 ,

 

I hope the information provided has been useful. Please let me know if you need further clarification or would like to continue the discussion.

 

If your question has been answered, please “Accept as Solution” and Give “Kudos” so others with similar issues can easily find the resolution.

 

Thank you.

Hi @Asil098,

 

I wanted to follow up and see if you had a chance to review the information shared. If you have any further questions or need additional assistance, feel free to reach out.

 

If the response answered your query, kindly “Accept as Solution” and Give “Kudos” to help others in the community benefit from it as well.

 

 

Nasif_Azam
Solution Sage
Solution Sage

Hey @Asil098 ,

A few points to clarify:

  1. Power Query vs. Data Model (DAX): If you created the calculated column using DAX in the data model, it will not be visible in Power Query, as Power Query and the data model are separate layers. To use the result in Power Query, you need to re-create the logic within Power Query using M language.

  2. Handling start_date > end_date: In Power Query, you can add a custom column with logic like this to calculate the time difference in minutes safely:

    if [start_date] <= [end_date] then
        Duration.TotalMinutes([end_date] - [start_date])
    else
        Duration.TotalMinutes([start_date] - [end_date]) * -1

    Or if you want to ignore negatives:

    Number.Abs(Duration.TotalMinutes([end_date] - [start_date]))
  3. DAX alternative for visuals or modeling: If you’re okay with using it in visuals instead of Power Query, your original DATEDIFF(start_date, end_date, MINUTE) DAX formula is correct. Just ensure you're using it in a measure or calculated column, and it’s being used in the correct context.

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.