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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.