Forum Discussion

rogerdea's avatar
rogerdea
Helper IV
4 years ago

DateTime difference to previous date/time

I am trying to calculate the difference in minutes between the date/time values in my table, to end up with a new column called "Diff" like in the example below.

 

I looked at similar example but couldn't get these working due to extra fields being used whereas i'm hoping this is much simpler as its just one column with date and time in.

 

Can anyone show me what the DAX would be for this and if it should be a measure or calculated column?

 

Thanks

5 Replies

  • rogerdea 

    Add the following DAX code in a new calculated column:

    Diff in Minutes = 
    
    VAR __CURRTIME = 'Table1'[DateTime]
    VAR __LASTTIME = 
        CALCULATE(
            MAX('Table1'[DateTime]),
            'Table1'[DateTime]<__CURRTIME,
            REMOVEFILTERS('Table1')
        )
    VAR __RESULT = 
        DATEDIFF( __LASTTIME, __CURRTIME , MINUTE )
    RETURN
        __RESULT
    
    

     

    • rogerdea's avatar
      rogerdea
      Helper IV

      Thank you Fowmy 

       

      I've applied that solution to my data but it's giving strange results, and i'm not sure why.  I've pasted the DAX with the actual real table names, have i applied the solution correctly?

      Thanks

       

       

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rogerdea ,

    According to your descriptions, i guess you add a measure with Fowmy  dax formula to table visual. if you want to show the date according to the filter, please add a new column to the original table, then add the datetime column to slicer visual.

     

    Best regards,
    Community Support Team_ Binbin Yu