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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
amiller5
Helper II
Helper II

Date diff with an if statement?

Hello - 

I am trying to create a Turn around time calculation using a date for opened and closed. When the file has nothing in the date closed column, I want the calculation to be against another date in a key table I have. Is that possible to do with date diff? See screen shot of data and current calculated column for date diff - but note when there is not closed date, it remains blank.

amiller5_0-1657729933168.png

Different table has the refresh month date as a date key

 

amiller5_2-1657729965681.png

 

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@amiller5 try this:

 

Number of Months = 
DATEDIFF( 
    'Table'[Open Date Column],
    COALESCE ( 
           'Table'[Closed Date Column], 
           CALCULATE ( MAX ( 'Key Date Table'[Key Date Column] ) 
    ),
    MONTH
)

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@amiller5 try this:

 

Number of Months = 
DATEDIFF( 
    'Table'[Open Date Column],
    COALESCE ( 
           'Table'[Closed Date Column], 
           CALCULATE ( MAX ( 'Key Date Table'[Key Date Column] ) 
    ),
    MONTH
)

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

gauthamboppana
Solution Specialist
Solution Specialist

@amiller5  - Yes, it is possible. Is there a relationship between these two date columns? The sample syntax is like below.

Measure = 
Switch(TRUE(),
Table[Date1] = "",  DATEDIFF('Table'[StartDate],'Table'[End Date1],MONTH),
 DATEDIFF('Table'[StartDate],'Table'[End Date2],MONTH),
)

amiller5_0-1657730965784.png

No - the date key and the service 1 table do not have a relationship. The date key table is an input table for me to calculate other measures on. We use this specifically for looking at KPIs but retrospecitvely - so we are grabbing updated data in July to assess June's measures.

Maybe give this a try.

 

Test =
VAR _End =
IF(
    SELECTEDVALUE('Table1'[Date/Time Closed]) = BLANK(),
    EOMONTH(MAX('OtherTable'[Date]), 0),
    SELECTEDVALUE('Table1'[Date/Time Closed])
)
RETURN
    DATEDIFF(SELECTEDVALUE('Table1'[Date/Time Opened]), _End, DAY)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.