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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Datediff Formula question

Hi Guys, 

 

I cant get this formula to work the way I want it.  This formula works perfectly but I also want it to caluclate If the resolved date is empty, I want it to calualte created date to current date to know the amount of days that have passed by without the ticket being resolved.  I have also attached the excel version of the fomula that works amazingly well but I am having issues fully convering it to power bi. 

 

Mar 19 Open Age = If(AND('FreshService RAW DATA'[Created Date]<=Date(2019,3,31),'FreshService RAW DATA'[Resolved Date]>Date(2019,3,31)),DATEDIFF('FreshService RAW DATA'[Created Date],DATE(2019,3,31),Day))
 
 
 
Excel formula that actially workes.
 
 =IF(AND($AE38768<=AV$6,$AF38768>AV$6),AV$6-$AE38768,"")

 

SamuelTesf_2-1642205361549.png

 


 

 

 

 

Created DayResolved DayClosed DayCreated monthResolved monthClosed monthCreated to Resolved DurationOpen?Jan 19 Open AgeFeb 19 Open AgeMar 19 Open AgeApr 19 Open AgeMay 19 Open AgeJun 19 Open AgeJul 19 Open AgeAug 19 Open AgeSep 19 Open AgeOct 19 Open AgeNov 19 Open AgeDec 19 Open AgeJan 20 Open AgeFeb 20 Open AgeMar 20 Open AgeApr 20 Open AgeMay 20 Open AgeJun 20 Open Age
01/08/19  Jan-2019  OpenY235182112143173204235265296326357388417448478509539
07/23/19  Jul-2019  OpenY      83969100130161192221252282313343
09/18/19  Sep-2019  OpenY        124373104135164195225256286
10/17/19  Oct-2019  OpenY         144475106135166196227257
11/05/19  Nov-2019  OpenY          255687116147177208238
11/14/19  Nov-2019  OpenY          164778107138168199229
01/03/20  Jan-2020  OpenY            285788118149179
01/17/20  Jan-2020  OpenY            144374104135165
01/27/20  Jan-2020  OpenY            4336494125155
02/05/20  Feb-2020  OpenY             245585116146
02/05/20  Feb-2020  OpenY             245585116146
02/11/20  Feb-2020  OpenY             184979110140
03/05/20  Mar-2020  OpenY              265687117
04/01/20  Apr-2020  OpenY               296090
04/20/20  Apr-2020  OpenY               104171
05/05/20  May-2020  OpenY                2656
06/10/20  Jun-2020  OpenY                 20
06/26/20  Jun-2020  OpenY                 4
06/30/20  Jun-2020  OpenY                 0
1 ACCEPTED SOLUTION

I see you wanted to do is to calculate for those rows created date is before 7/31/2020 and resolved date is blank or after 7/31/2020.

 

For the rows, you want to adjust the resolved date blank as the cut off date "7/31/2020".

 

 

 

Tryout 2 Open Age = 
IF ( 
   -- only those rows with created date <= 7/31/2020 and resolved date as blank or after 7/31/2020
  ('FreshService RAW DATA'[Created Date] <= Date(2020,7,31) 
   && ( 
           IsBlank('FreshService RAW DATA'[Resolved Date]
           || 'FreshService RAW DATA'[Resolved Date] > Date(2020,7,31) 
       )
  ), 

  DATEDIFF(
   'FreshService RAW DATA'[Created Date], 

   IF (
       IsBlank('FreshService RAW DATA'[Resolved Date] ), 
       Date(2020,7,31), 
       'FreshService RAW DATA'[Resolved Date]
   )
  , DAY)
)

 

 

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

@sevenhills 

 

I reward the fomula to its simplest form,  Can this be done below in powe bi? I did it but got an error message. 

 

I wanted to calculate the date difference between CREATED DATE that’s Less than or equal to (<=) 7/31/2020 and RESOLVED DATE that’s higher then (>) 7/31/2020. But if RESOLVED DATE is blank Then calculate date difference between 7/31/2020 and CREATED DATE.

 

Tesst 4 = DATEDIFF('FreshService RAW DATA'[Created Date] <=DATE(2020,7,31), 'FreshService RAW DATA'[Resolved Date] >DATE(2020,7,31), Day) &&ISBLANK('FreshService RAW DATA'[Resolved Date]), DATEDIFF(Date(2020,7,31), 'FreshService RAW DATA'[Created Date))

I see you wanted to do is to calculate for those rows created date is before 7/31/2020 and resolved date is blank or after 7/31/2020.

 

For the rows, you want to adjust the resolved date blank as the cut off date "7/31/2020".

 

 

 

Tryout 2 Open Age = 
IF ( 
   -- only those rows with created date <= 7/31/2020 and resolved date as blank or after 7/31/2020
  ('FreshService RAW DATA'[Created Date] <= Date(2020,7,31) 
   && ( 
           IsBlank('FreshService RAW DATA'[Resolved Date]
           || 'FreshService RAW DATA'[Resolved Date] > Date(2020,7,31) 
       )
  ), 

  DATEDIFF(
   'FreshService RAW DATA'[Created Date], 

   IF (
       IsBlank('FreshService RAW DATA'[Resolved Date] ), 
       Date(2020,7,31), 
       'FreshService RAW DATA'[Resolved Date]
   )
  , DAY)
)

 

 

Anonymous
Not applicable

@sevenhills 

 

It working great but is there a way to restrict Resolved date to any date resolved date greater then 7/31/2020. What I was saying was I am having trouble adding this to the formula 

 

'FreshService RAW DATA'[Resolved Date] >DATE(2020,7,31)
 
I was wondering if you had a suggestion on were to added it in the formula. When ever I try to add it I run into errors.
'FreshService RAW DATA'[Resolved Date] >DATE(2020,7,31)
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, I did a test reference as follows:

 

Colopen_age = 
IF (
    'FreshService RAW DATA'[Created Day] <= DATE ( 2019, 10, 31 )
        && 'FreshService RAW DATA'[Resolved Day] >= DATE ( 2019, 10, 31 ),
    DATEDIFF ( 'FreshService RAW DATA'[Created Day], DATE ( 2019, 10, 31 ), DAY )
)

 

vhenrykmstf_1-1642494961627.png

vhenrykmstf_2-1642495017429.png


If the problem is still not resolved, please point it out. Looking forward to your feedback.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

@v-henryk-mstf 

 

Your formula works great when there is a reolved date. The issue is when there is no resolved date. I want it to calculate from Created date to the date I input like 12/31/2021.  In excel I am easly able to that that but not power bi. 

 

This formula works great except for the last part. 

Mar 19 Open Age = If(AND('FreshService RAW DATA'[Created Date]<=Date(2019,3,31),'FreshService RAW DATA'[Resolved Date]>Date(2019,3,31)),DATEDIFF('FreshService RAW DATA'[Created Date],DATE(2019,3,31),Day))

Hi @Anonymous ,

 

There are some calculation logic differences between powerbi and excel. In powerbi, each calculation column needs to be formed by creating a separate formula. It is not like excel where you can form multiple columns based on the same calculation logic.

If you want to display it in the way shown in the screenshot, you can only do so by creating separate calculated columns.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

sevenhills
Super User
Super User

I updated the reply ... ignore this

 

Try replace and see if this work for you

 

 

'FreshService RAW DATA'[Created Date]

 

 

as

 

If( IsBlank('FreshService RAW DATA'[Created Date]), Today())

 

 

Anonymous
Not applicable

@sevenhills 

 

What do you mean like this?  Mar 19 Open Age = If(Isblank('FreshService RAW DATA'[Created Date],Today())<=Date(2019,3,31),'FreshService RAW DATA'[Resolved Date]>Date(2019,3,31)),DATEDIFF('FreshService RAW DATA'[Created Date],DATE(2019,3,31),Day))

 

Mar 19 Open Age = 
IF ( 
  ('FreshService RAW DATA'[Created Date] <= Date(2019,3,31) 
   && IsBlank('FreshService RAW DATA'[Resolved Date]
  ), 

  DATEDIFF('FreshService RAW DATA'[Created Date], TODAY(), DAY),

  DATEDIFF('FreshService RAW DATA'[Created Date], 'FreshService RAW DATA'[Resolved Date], Day)
)

 

 

Change to your needs, added code for is blank chek and use Today in case of it ... 

Anonymous
Not applicable

@sevenhills 

 

Thank you so much this works great. I have one question for you. Would it be possible to include this FreshService RAW DATA'[Resolved Date] > Date(2020,7,31)? I tried it but it keeps on giving me errors.

 

IF('FreshService RAW DATA'[Created Date] <=DATE(2020,7,31) && ISBLANK('FreshService RAW DATA'[Resolved Date]),DATEDIFF('FreshService RAW DATA'[Created Date], DATE(2020,7,31), Day), DATEDIFF('FreshService RAW DATA'[Created Date],'FreshService RAW DATA'[Resolved Date],Day))

Tryout 2 Open Age = 
IF ( 
  ('FreshService RAW DATA'[Created Date] <= Date(2020,7,31) 
   && IsBlank('FreshService RAW DATA'[Resolved Date]
  ), 

  DATEDIFF('FreshService RAW DATA'[Created Date], Date(2020,7,31), DAY),

  DATEDIFF('FreshService RAW DATA'[Created Date], 'FreshService RAW DATA'[Resolved Date], Day)
)

 

Yes, it should work, I dont see any issues with it. What error you are getting?

U mean you want to check for the resolved date as either blank or has to be > Date(2020,7,31) ?

 

Try this and see

 

 

Tryout 2 Open Age = 
IF ( 
  ('FreshService RAW DATA'[Created Date] <= Date(2020,7,31) 
   && ( 
           IsBlank('FreshService RAW DATA'[Resolved Date]
           || 'FreshService RAW DATA'[Resolved Date] > Date(2020,7,31) 
       )
  ), 

  DATEDIFF('FreshService RAW DATA'[Created Date], Date(2020,7,31), DAY),

  DATEDIFF('FreshService RAW DATA'[Created Date], 'FreshService RAW DATA'[Resolved Date], Day)
)

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.