Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HassanAshas
Helper V
Helper V

How to find the consecutive number of last months in which your Employee is inactive

I have the following data. 

 

Emp CodeMonthAllocationOvertime
1Nov-2211
1Oct-2210
1Sep-2211
1Aug-2211
1Jul-2200
1Jun-2210
1May-2200
2Nov-2200
2Oct-2201
2Sep-2200
2Aug-2211
2Jul-2210
2Jun-2210
2May-2200
3Nov-2200
3Oct-2200
3Sep-2200
3Aug-2200
3Jul-2200
3Jun-2200
3May-2200
4Nov-2200
4Oct-2200
4Sep-2200
4Aug-2200

 

 

What I need to know that for how many last consecutive months has the employees being inactive. Criteria of being inactive is their allocation + Overtime is 0. 

 

So, my expected result would be something similar to this,

 

Emp NoMonths Inactive
10
21 (has overtime = 1, in 2nd last month)
37
44
  

 

I made something like this as a measure to calculate the Inactive Months, but this is giving me wrong results, 

 

 

Months Inactive = 
MONTH(TODAY()) - 
MAXX(
        FILTER(
            Employee, 
            Employee[Allocation] = 0 && Employee[Overtime] = 0
        ), 
        MONTH(Employee[Month])
    )

 

 

Results I am getting with this code is the following, 

HassanAshas_0-1669710423659.png

Can anyone help me out on this?

 

You can download the Example Workbook from here: https://drive.google.com/file/d/1weyjGYG6yZdGgB47FwkiVgfu36m7UzAR/view?usp=sharing

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Here is a measure expression that shows one way to do it.

ppm1_0-1670115727435.png

 

Months Inactive =
VAR vMaxDate =
    MAX ( Employee[Month] )
VAR vMinDate =
    MIN ( Employee[Month] )
VAR vLastActive =
    CALCULATE (
        MAX ( Employee[Month] ),
        OR ( Employee[Allocation] = 1, Employee[Overtime] = 1 )
    )
VAR vResult =
    IF (
        ISBLANK ( vLastActive ),
        DATEDIFF ( vMinDate, vMaxDate, MONTH ) + 1,
        DATEDIFF ( vLastActive, vMaxDate, MONTH )
    )
RETURN
    vResult

 

Pat

Microsoft Employee

View solution in original post

1 REPLY 1
ppm1
Solution Sage
Solution Sage

Here is a measure expression that shows one way to do it.

ppm1_0-1670115727435.png

 

Months Inactive =
VAR vMaxDate =
    MAX ( Employee[Month] )
VAR vMinDate =
    MIN ( Employee[Month] )
VAR vLastActive =
    CALCULATE (
        MAX ( Employee[Month] ),
        OR ( Employee[Allocation] = 1, Employee[Overtime] = 1 )
    )
VAR vResult =
    IF (
        ISBLANK ( vLastActive ),
        DATEDIFF ( vMinDate, vMaxDate, MONTH ) + 1,
        DATEDIFF ( vLastActive, vMaxDate, MONTH )
    )
RETURN
    vResult

 

Pat

Microsoft Employee

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.