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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Custom Column - Add condition to date calculation

Hi All,

 

I have a custom column which gives the duration of problem ticket records from when they are open to when they are closed ([closed_date]-[created_date]).

 

However, as some of the tickets are still open, I would like to add a condition that returns the duration between [created_date] and [today] if [closed_date] is null.

 

I am thinking it may need to be an IF statement of some kind but dont know how to achieve this.  Is anyone able to help please?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @shaowu459  and @PhilipTreacy,

 

Apologies for the delayed response.  I wanted to thank you both; though the formulae you both provided did not quite work for me, I was able to work it out using your examples by snipping out this part:

 

= if [closed_date]=null then DateTime.LocalNow()-[created_date] else [closed_date]-[created_date]

 

Thanks to each of you for pointing me in the right direction! 🙂

View solution in original post

4 REPLIES 4
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Glad to hear the issue is solved. You can accept your reply as solution, that way, other community members could easily find the answer when they get same issues.


Best Regards,
Community Support Team _ Yingjie Li


Anonymous
Not applicable

Hi @shaowu459  and @PhilipTreacy,

 

Apologies for the delayed response.  I wanted to thank you both; though the formulae you both provided did not quite work for me, I was able to work it out using your examples by snipping out this part:

 

= if [closed_date]=null then DateTime.LocalNow()-[created_date] else [closed_date]-[created_date]

 

Thanks to each of you for pointing me in the right direction! 🙂

PhilipTreacy
Super User
Super User

Hi @Anonymous 

Try this, it assumes you are dealing with dates and not datetimes.

 

 

= Table.AddColumn(Source,"Duration",each if [closed_date]=null then DateTime.Date(DateTime.LocalNow()) - [created_date]  else [closed_date]-[created_date])

 

 

Phil 


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


shaowu459
Resolver II
Resolver II

Is this what you need?

= Table.AddColumn(Source,"Duration",each (if [closed_date]=null then DateTime.LocalNow() else [closed_date])-[created_date])

2020-10-28_18-41-02.jpg

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.

Top Solution Authors