Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Delta values

Hi,

 

How would I calculate Delta-values derived from a Date in combination with ID:

DateIDValuesDelta-values
DD-MM-YYYY  12:00188 
DD-MM-YYYY  12:00223 
DD-MM-YYYY  12:151891
DD-MM-YYYY  12:152252
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Increase the index through power query

    2. Create calculcated column.

    Delta-values =
    var _lastindex=
    CALCULATE(MAX('Table'[Index]),FILTER(ALL('Table'),[Metern]=EARLIER([Metern])&&[Index]<EARLIER([Index])))
    
    var _lastdata=
    CALCULATE(SUM('Table'[Data]),FILTER('Table',[Index]=_lastindex))
    
    return IF(_lastindex=BLANK(),BLANK(),[Data]-_lastdata)

    3. Result.

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

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

9 Replies

  • Anonymous , Try formula

     

    Column = var _1 = MAXX(FILTER('Table',[ID] =EARLIER('Table'[ID]) && [Date] <EARLIER('Table'[Date])), LASTNONBLANKVALUE('Table'[Date],'Table'[Values]))
    return if( ISBLANK(_1), BLANK(),[Values]-_1)
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

     

    Here are the steps you can follow:

    1. Create calculcated column.

    Delta-values =
    var _max=MAX('Table'[Date])
    var _min=MIN('Table'[Date])
    var _1=
    CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[Date]=_max&&'Table'[ID]=EARLIER('Table'[ID])))
    -
    CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[Date]=_min&&'Table'[ID]=EARLIER('Table'[ID])))
    
    return IF('Table'[Date]=_min,BLANK(),_1)
    

    2. Result.

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

    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

      Thanks Liu,

       

      I followed your steps, and also ended up with a column - however the values seems wrong and does not reflect the expected delta-value as in your example,

       

      Where did I go wrong?

       

       

       

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    To fact that you can do something does not mean you should. Such data transformations are best done (and easy!) in Power Query. DAX should be used to create calculated columns only as the very, very, very last resort. There are many reasons behind this, two of them being poor compression and model bloat if done through DAX. Please use Power Query - the right tool for the job.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Daxer,

      That all makes sense,

      However, I would still need the DAX code for it,

       

      Any input for the DAX code highly appreciated!

      • Anonymous's avatar
        Anonymous
        Not applicable

        No, you don't need DAX. You need M - the language of Power Query. That's the whole point. DAX is for data analysis. M is for data munging.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Increase the index through power query

    2. Create calculcated column.

    Delta-values =
    var _lastindex=
    CALCULATE(MAX('Table'[Index]),FILTER(ALL('Table'),[Metern]=EARLIER([Metern])&&[Index]<EARLIER([Index])))
    
    var _lastdata=
    CALCULATE(SUM('Table'[Data]),FILTER('Table',[Index]=_lastindex))
    
    return IF(_lastindex=BLANK(),BLANK(),[Data]-_lastdata)

    3. Result.

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

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