Forum Discussion

Jay92SG's avatar
Jay92SG
New Member
3 years ago
Solved

Calculate difference between current month and previous month for cumulative data

Hi, i have a report that i can extract on a monthly basis. 

 

For example,

 

Date                Asset ID      Transaction
1 Dec 2022          123               0
1 Jan 2023          123             1000
1 Feb 2023         123             1000
1 Mar 2023         123             1000

I need to get the monthly additions for Mar 2023, i will need to take the transaction for Mar23 (1000) and deduct Feb23 (1000) to get 0 additions. It would mean that for Jan23, it is $1000 addition using Jan23 (1000) -  Dec22(0).

the report is a long list with many different asset ID. can anyone help me? i have tried the below but doesnt work. I am thinking i will need to summarize by asset ID first, and for each row, compute the difference by looking up to the previous month transaction. 
AdditionCM = (CALCULATE( sum(ZFA0006[Transaction]) , LASTDATE(ZFA0006[Date])) )- (CALCULATE( sum(ZFA0006[Transaction]) , PREVIOUSMONTH(ZFA0006[Date])) )


  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Jay92SG ,

     

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

    (1) My test data is the same as yours.

    (2) We can create a measure. 

    addition using = 
    var _a=CALCULATE(SUM('Table'[Transaction]),FILTER(ALL('Table'),'Table'[Asset ID]=MAX('Table'[Asset ID]) && YEAR('Table'[Date])=YEAR(EOMONTH(MAX('Table'[Date]),-1)) && MONTH('Table'[Date])=MONTH(EOMONTH(MAX('Table'[Date]),-1))))
    return MAX('Table'[Transaction])-_a

    (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. 

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Jay92SG ,

     

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

    (1) My test data is the same as yours.

    (2) We can create a measure. 

    addition using = 
    var _a=CALCULATE(SUM('Table'[Transaction]),FILTER(ALL('Table'),'Table'[Asset ID]=MAX('Table'[Asset ID]) && YEAR('Table'[Date])=YEAR(EOMONTH(MAX('Table'[Date]),-1)) && MONTH('Table'[Date])=MONTH(EOMONTH(MAX('Table'[Date]),-1))))
    return MAX('Table'[Transaction])-_a

    (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.