Forum Discussion

wy_khoo's avatar
wy_khoo
Frequent Visitor
2 years ago
Solved

Substract first value in the table column

Hi, 

 

I have a matrix table showing data for each month.

 

Can you please advise what is the formula to calculate difference between last month vs first month.

 

For example: 14-49 = -35

 

Thank you in advance!

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi wy_khoo ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data. 

    (2) We can create a measure. 

    Measure = 
    var _first_date=CALCULATE(MIN('Table'[date]),ALLSELECTED('Table'))
    var _first_value=CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),MONTH('Table'[date])=MONTH(_first_date) && YEAR('Table'[date])=YEAR(_first_date)))
    var _value=CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),YEAR('Table'[date])=YEAR(MAX('Table'[date])) && MONTH('Table'[date])=MONTH(MAX('Table'[date]))))
    RETURN _value-_first_value

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi wy_khoo ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data. 

    (2) We can create a measure. 

    Measure = 
    var _first_date=CALCULATE(MIN('Table'[date]),ALLSELECTED('Table'))
    var _first_value=CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),MONTH('Table'[date])=MONTH(_first_date) && YEAR('Table'[date])=YEAR(_first_date)))
    var _value=CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),YEAR('Table'[date])=YEAR(MAX('Table'[date])) && MONTH('Table'[date])=MONTH(MAX('Table'[date]))))
    RETURN _value-_first_value

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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

    • wy_khoo's avatar
      wy_khoo
      Frequent Visitor

      Hi Anonymous , thank you for your solution. It works!