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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.