Forum Discussion

askpbiuser's avatar
askpbiuser
Icon for Helper I rankHelper I
2 years ago
Solved

DAX Previous value from measure

Hi All, I have two fact tables connected with a dimension table. The fact tables have a many-to-one relationship with Dimension. I have the below fields displayed in a table in Power BI visual. ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Thanks lbendlin 

    Hi, askpbiuser 

    Let's assume that your A, B, Cumulative sum of A, and Cumulative sum of A-B are all metrics. If not, you should adjust my DAX expression below appropriately.

    I used the following DAX expression:

    Output1 =
    VAR _currIndex =
        SELECTEDVALUE ( 'Table'[Index] )
    VAR _previousvalue =
        CALCULATE (
            [Measure of Cumulative sum of A-B],
            FILTER ( ALL ( 'Table' ), 'Table'[Index] < _currIndex )
        )
    VAR _result = [Measure of Cumulative sum of A-B] - _previousvalue
    RETURN
        SWITCH ( TRUE (), _result > 0, _result, 0 )
    

    Here are the results:

    I've uploaded the PBIX file I used this time below.

     

     

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li

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