How to calculate current period compared to the one before.
This blog will provide step-by-step instructions on how to create Current period vs Previous period KPI.
Step 1 : First I start by creating the needed parameters and calculated fields.
Parameter:
Choose month
Create a parameter for the month we would like to make comparison for:
![](https://www.thedataschool.co.uk/content/images/2022/06/image-76.png)
Calculated fields
Current month
![](https://www.thedataschool.co.uk/content/images/2022/06/image-77.png)
DATETRUNC('month',(MAX([Order Date])))
![](https://www.thedataschool.co.uk/content/images/2022/06/image-78.png)
if DATETRUNC('month', [Order Date])= DATETRUNC('month', [Choose month]) then 'Current' ELSEIF DATETRUNC('month', [Order Date])= DATETRUNC('month', DATEADD('month',-1,[Choose month])) then 'Previous' else'Other' END
Step 2: I drag Month/Year on the rows shelf and Sales on Text on the Marks card adn Timeperiod onto the Colour shelf. I also show the Choose month filter. We can clearly see that the calculations so far work. We have the Current month in blue, the Previous month in red and all other month in gray.
![](https://www.thedataschool.co.uk/content/images/2022/06/image-79.png)
Step 3: I will now hide all the ‘Other’ values and this leaves me with this month and previous month values only.
![](https://www.thedataschool.co.uk/content/images/2022/06/image-80.png)
Step 4: Drag Timeperiod, Sales and MY(Order Date) on the detail marks.
Step 5: Make a table calculation for the sales pill with the following settngs:
![](https://www.thedataschool.co.uk/content/images/2022/06/image-81.png)
Step 6: Change the Sales with the calculated filed from ‘detail’ to ‘text.
Step 7: Change the chart type to text
From here you can format the sheet as needed, hide the fields that are not needed. For this example I have kept only the chosen month.
And here is the result!
![](https://www.thedataschool.co.uk/content/images/2022/06/image-82.png)
Voila!