Forum Discussion

matrix_user's avatar
matrix_user
Helper III
3 years ago
Solved

Subtracting values up column databases

Hello,

 

What DAX measure (or column) would be required if I wanted to count the difference in values within a column of a fact table - per year?

 

Below the subtract of 8 (2021) from 5 (2010) gives me 3.

 

Kudos to who can help.

 

Thank!

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a measure.

     

     

     

    Diff: =
    VAR _previousvalue =
        CALCULATE (
            [Total coffees:],
            OFFSET ( -1, ALL ( Data[Year] ), ORDERBY ( Data[Year], ASC ) )
        )
    RETURN
        IF (
            NOT ISBLANK ( _previousvalue ) && HASONEVALUE ( Data[Year] ),
            [Total coffees:] - _previousvalue
        )
    

2 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a measure.

     

     

     

    Diff: =
    VAR _previousvalue =
        CALCULATE (
            [Total coffees:],
            OFFSET ( -1, ALL ( Data[Year] ), ORDERBY ( Data[Year], ASC ) )
        )
    RETURN
        IF (
            NOT ISBLANK ( _previousvalue ) && HASONEVALUE ( Data[Year] ),
            [Total coffees:] - _previousvalue
        )