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:

power bi

I have those 2 tables:

Table1 Calendar
power bi power bi

In the “calendar”, I will add this column:

  • monthnum: YEAR([argument])*12+ROUNDUP(MONTH([argument]),0)
power bi power bi

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)
power bi power bi

I will create a relationship between “opened month” and “calendar”:

power bi

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”
    power bi
  • 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)
    power bi
  • 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))
    power bi
  • 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)
    power bi

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
    power bi
  • 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
    power bi power bi
  • 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
    power bi power bi

Interesting Topics