Power BI: calculate values of a previous/next month and within a range based on selected month with a filter
I will explain the way to calculate the value of the next month after selecting a month in a slicer and also within a range based on another date column:
I have those 2 tables:
| Table1 | Calendar |
![]() |
![]() |
In the “calendar”, I will add this column:
- monthnum: YEAR([argument])*12+ROUNDUP(MONTH([argument]),0)
In the “table1”, I will add 3 columns:
- Opened month: using the “data groups”
- closemonnum: same formula as “monthnum”
- Closed month: using the “data groups” (optional)
I will create a relationship between “opened month” and “calendar”:
I will create 4 measures:
- To show the name of the next month:
FORMAT(DATE(1,CONVERT(VALUES('table'[argument])+1,DATETIME),1),"MMMM")
NOTE: to get the previous month, change “+1” by “-1”
- To calculate how many incident tickets I have for the next month:
CALCULATE(CALCULATE(COUNT('table1'[argument]),ALL('table2'[argument1])),'table2'[argument2]=
MAX('table2'[argument2])+1)
- To calculate how many incident tickets I have for the selected month based on the range of closed date:
CALCULATE(COUNT('table1'[argument1]),FILTER('table1','table1'[argument2]=SELECTEDVALUE('table2'
[argument])||'table1'[argument2]=SELECTEDVALUE('table2'[argument])+1))
- To calculate how many incident tickets I have for the next month based on the range of closed date:
CALCULATE(CALCULATE(CALCULATE(COUNT('table1'[argument1]),ALL('table2'[argument1])),'table2'
[argument2]=MAX('table2'[argument2])+1),'table1'[argument2]=MAX('table2'[argument2])+1||'table1'
[argument2]=MAX('table2'[argument2])+2)
For my visuals, I will create a slicer using the “calendar” and when I select for instance “September 2024”:
- Measure: it is showing the next month name
- Measure 2: it is showing the number of incident for the next month
- Measure 3: it is showing the number of incidents for the selected month but only the ones closed on the selected month and the next month
- Measure 4: it is showing the number of incidents for the next month but only the ones closed on the next month and the next next month
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...
-
Refresh Power BI
From the Power BI Service, I can set refresh but, for instance, there is no option to do it monthly or each time a change is made...
-
Power BI alerts to be sent by email from an excel file based on condition
I will explain how to send a list of emails from an excel file after creating alerts...








