Forum Discussion
Calculating a difference between two periods
Hello Everyone. A bit of a background: in my work we rarely use actual calendar months (thus cannot use time intelligence functions), but we use periods instead as demonstrated in the sample dataset I have included. And currently I am struggling to find a way to calculate the difference in total revenue between one period and the period before it (i.e., period-on-period change) in Power BI. Could somebody please help me with that? I have included the desired result at the bottom of this post.
| Period | Week | Revenue |
| Period 1 | Week 1 | 10 |
| Period 1 | Week 1 | 24 |
| Period 1 | Week 2 | 67 |
| Period 1 | Week 2 | 34 |
| Period 1 | Week 3 | 78 |
| Period 2 | Week 4 | 34 |
| Period 2 | Week 4 | 54 |
| Period 2 | Week 4 | 23 |
| Period 2 | Week 5 | 67 |
| Period 2 | Week 6 | 34 |
| Period 2 | Week 6 | 54 |
| Period 3 | Week 7 | 45 |
| Period 3 | Week 7 | 78 |
| Period 3 | Week 8 | 90 |
| Period 3 | Week 8 | 123 |
| Period 3 | Week 8 | 12 |
| Period 3 | Week 8 | 34 |
| Period 3 | Week 9 | 5 |
Desired Result:
| Period | Total Revenue | Revenue Difference |
| Period 1 | 213 | |
| Period 2 | 266 | 53 |
| Period 3 | 387 | 121 |
So, I would like to see the difference in total revenue between one period and the period before it (Revenue Differnce column). For example, Period 3 - Period 2, Period 2 - Period 1 and so on. It is a similar concept to a month-on-month calculatinon. Any help would be appreciated. Thanks:)
you can try to create a measure
Measure =VAR _last=maxx(FILTER(all('Table'),'Table'[Period]<max('Table'[Period])),'Table'[Period])return if(_last="",BLANK(),sum('Table'[Revenue])-SUMX(FILTER(ALL('Table'),'Table'[Period]=_last),'Table'[Revenue]))pls see the attachment below
2 Replies
- mugdha395290New Member
Hi, Alex35749
First, group by Period in Power Query which will give you this-Add a column PeriodNumber -
Next step will be to create a measure to calculate difference with previous revenue-
It will give the desired output-
Hope this helps 🙂
- ryan_mayuSuper User
you can try to create a measure
Measure =VAR _last=maxx(FILTER(all('Table'),'Table'[Period]<max('Table'[Period])),'Table'[Period])return if(_last="",BLANK(),sum('Table'[Revenue])-SUMX(FILTER(ALL('Table'),'Table'[Period]=_last),'Table'[Revenue]))pls see the attachment below