In this article, we will learn how we can show the aggregate value of the previous number of months within the same table in Power BI using Measures.
I have a scenario, in which I have one table that has Cash and Charge values in a table. I want to show a monthly sum of charges. I also want to show the sum of charges from the previous month as well as the previous two months within the table. Please refer to the following output screen.
Let’s say there is a month, for instance May, and for May the previous month is April and the month before that is March.
So, I need the end result as – For May – current month charges are 660, previous month charges are 1237 ( which is similar to April’s charges) and the second previous month charges are 113 (of March).
In order to achieve this, we have created some calculated columns, calendar tables, and measures.
I have added a sample file for your reference on the GitHub. You can directly download the sample Power BI file and the data source file using this link - Download Example.
Let’s get started!
Create a Calendar table. To create a calendar table, go to the Modeling pane and click on the "New Table" option.