Forum Discussion
Comparing Periods in the same table
I am sure this is a fairly straightforward problem for most but I'm fairly new to Power BI and any help is appreciated!
I have a single table that compiles monthly reporting information. I want to be able to calculate the difference between current month Output and Previous Month Output. What I can't figure out is how to do this dynamically so that each time a new month is added, the measure will compare the max reporting period with the max minus one?
Thanks in advance!
| Project | Reporting Period | Output |
| A | 01/01/2021 | 100 |
| B | 01/01/2021 | 80 |
| C | 01/01/2021 | 150 |
| A | 01/02/2021 | 120 |
| B | 01/02/2021 | 90 |
| C | 01/02/2021 | 140 |
| A | 01/03/2021 | 110 |
| B | 01/03/2021 | 95 |
| C | 01/03/2021 | 140 |
| etc. |
Hi GJUDGE
You can use Edate() function to get last period, for example,
Last Period = var _currentDate=MAX('table'[date]) var _lastDate=EDATE(_currentDate,-1) return CALCULATE(SUM('table'[Output]),'table'[date]=_lastDate)Kindly note: Edate() function has some limitations,
If you can't use Edate() on some occasions, you can try this measure,
Last Period = var _maxDate=MAX('table'[date]) var _lastDate=DATE(YEAR(_maxDate),MONTH(_maxDate)-1,1) return CALCULATE(SUM('table'[Output]),'table'[date]=_lastDate)Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
18 Replies
- vanessafvgCommunity Champion
so you saying you want to sum this months and sum last month and then work out the difference as a change %?
- GJUDGEHelper II
Not even a % change, just the difference, but my main worry is not needing to update the measure each month every time a new months worth of data is added. Any tips are welcomed!
- jppv20Solution Sage
hI GJUDGE ,
You can create this measure:
OutputDifference =var Output = SUM('Table'[Output])var OutputLastPeriod = CALCULATE(SUM('Table'[Output]),ALLEXCEPT('Table','Table'[Project]),PREVIOUSMONTH('Table'[Reporting Period]))ReturnOutput-OutputLastPeriodThis will give the following result:Jori
If I answered your question, please mark it as a solution to help other members find it more quickly.
Connect on Linkedin- GJUDGEHelper II
jppv20 This isn't quite giving me what I need (but I appreciate your help!). When I put the measure into matrix view I get the following, which appears to be summing all the output months. How can I adapt the measure to only show the change for the latest month? i.e. -10 for project A, 5 for project B and 0 for project C with a total of -5?
- jppv20Solution Sage
GJUDGE Thanks for clarifying, I understand the issue better now. Do you need this to be solved in the measure? Otherwise you can add a date filter to select the month for which you want to see the change:
Jori
If I answered your question, please mark it as a solution to help other members find it more quickly.
Connect on Linkedin