Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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,"")

 

 


 

 

 

 

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
  • 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)
    )

     

     

12 Replies

  • 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's avatar
      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))

      • sevenhills's avatar
        sevenhills
        Super User

         

        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 ... 

  • v-henryk-mstf's avatar
    v-henryk-mstf
    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 )
    )

     


    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's avatar
      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))

      • v-henryk-mstf's avatar
        v-henryk-mstf
        Community Support

        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.

  • Anonymous's avatar
    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)
  • Anonymous's avatar
    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))

    • sevenhills's avatar
      sevenhills
      Super User

      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)
      )