cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HassanAshas
Helper I
Helper I

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
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.