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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Calculating days difference

I am using Direct Query for my Power BI report. I want to calcualte the days taken to close an opportunity, using 2 columns "Actual Close Date" and "Created On". 

I am using the following Dax Measure to calculate the difference:

2.PNG

 

When I use this measure on a visual I get the following error:

Capture.PNG

 

The same DAX measure works perfectly fine when I am using import query mode. 

1 ACCEPTED SOLUTION
manvishah17
Responsive Resident
Responsive Resident

HI @Anonymous , 
I also encountered this error sometimes , it may happen if there are blank values in columns , to troubleshoot it , you can try this code 

Days_to_Close = 
IF(
    NOT(ISBLANK('your_table_name'[Actual Close Date])) && NOT(ISBLANK('your_table_name'[Created On])),
    DATEDIFF('your_table_name'[Created On], 'your_table_name'[Actual Close Date], DAY),
    BLANK()
)

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

View solution in original post

2 REPLIES 2
manvishah17
Responsive Resident
Responsive Resident

HI @Anonymous , 
I also encountered this error sometimes , it may happen if there are blank values in columns , to troubleshoot it , you can try this code 

Days_to_Close = 
IF(
    NOT(ISBLANK('your_table_name'[Actual Close Date])) && NOT(ISBLANK('your_table_name'[Created On])),
    DATEDIFF('your_table_name'[Created On], 'your_table_name'[Actual Close Date], DAY),
    BLANK()
)

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

v-cgao-msft
Community Support
Community Support

Hi @Anonymous ,

You mentioned that this is a measure, try using MAX() or SELECTEDVALUE() to get the current value.

Days Taken to Close a Deal =
DATEDIFF (
    MAX ( 'close opportunties'[Created On] ),
    MAX ( 'close opportunties'[Actual Close Date] ),
    DAY
)

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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