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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
maxkhan
Frequent Visitor

DAX Query

aoinac

1 ACCEPTED SOLUTION
Poojara_D12
Super User
Super User

Hi @maxkhan 

Can you please use this dax:

 

Actual_Duration = 
IF(
    ISBLANK('Table'[Actual_EndTime]), 
    'Table'[Planned_Duration], 
    DATEDIFF('Table'[Actual_StartTime], 'Table'[Actual_EndTime], MINUTE) / 60
)

 

 

  • If Actual_EndTime is null, it will show the Planned_Duration.
  • If Actual_EndTime has a value, it will calculate the difference between Actual_StartTime and Actual_EndTime in hours.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

View solution in original post

5 REPLIES 5
Poojara_D12
Super User
Super User

Hi @maxkhan 

Can you please use this dax:

 

Actual_Duration = 
IF(
    ISBLANK('Table'[Actual_EndTime]), 
    'Table'[Planned_Duration], 
    DATEDIFF('Table'[Actual_StartTime], 'Table'[Actual_EndTime], MINUTE) / 60
)

 

 

  • If Actual_EndTime is null, it will show the Planned_Duration.
  • If Actual_EndTime has a value, it will calculate the difference between Actual_StartTime and Actual_EndTime in hours.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Screenshot 2025-01-13 082131.png

hello @maxkhan 

 

you asked a logic for DAX but your display shows Power Query? Power Query uses M not DAX.

Irwan_0-1736722863322.png

What’s the Difference Between DAX and Power Query or M?

 

@Jihwan_Kim & @Poojara_D12 should have work in calculated column DAX not PQ.


Thank you.

maxkhan
Frequent Visitor

This doesn't work

 

Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below, and please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1736481975617.png

 

 

DATEDIFF function (DAX) - DAX | Microsoft Learn

 

Expected result CC =
IF (
    NOT ISBLANK ( data[actual_end_time] ),
    DATEDIFF ( data[actual_start_time], data[actual_end_time], HOUR ),
    data[planned duration]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.