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
Mannai
Helper I
Helper I

How to Calculate the Average Seniority for active employees

so i have a dataset of employees with start and end date and each employee have a seniority value as a number 

any ideas how to calculate the average seniority for only the active employees

 

Thanks

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Mannai,

I created some data:

vyangliumsft_0-1648103712182.png

Here are the steps you can follow:

1. Create calculated table.

Date = CALENDAR(DATE(2000,1,1),DATE(2022,12,31))

vyangliumsft_1-1648103712184.png

2. Create measure.

datediff =
var _select=SELECTEDVALUE('Date'[Year])
return
IF(
    MAX('FACT TABLE'[work])="no",
    YEAR(MAX('FACT TABLE'[End date]))-YEAR(MAX('FACT TABLE'[entry date])) ,
_select - YEAR(MAX('FACT TABLE'[entry date]) ))
average seniority for only the active employees =
AVERAGEX(FILTER(ALLSELECTED('FACT TABLE'),'FACT TABLE'[work]="yes"),[datediff])

3. Result:

Use [Year] of the Date table as the slicer.

When [work]=”no”, it means that it has left the company and does not need to change with the slicer

When [work]=”yes”, it means that there is no resignation, and it changes with the slicer

vyangliumsft_2-1648103712187.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @Mannai,

I created some data:

vyangliumsft_0-1648103712182.png

Here are the steps you can follow:

1. Create calculated table.

Date = CALENDAR(DATE(2000,1,1),DATE(2022,12,31))

vyangliumsft_1-1648103712184.png

2. Create measure.

datediff =
var _select=SELECTEDVALUE('Date'[Year])
return
IF(
    MAX('FACT TABLE'[work])="no",
    YEAR(MAX('FACT TABLE'[End date]))-YEAR(MAX('FACT TABLE'[entry date])) ,
_select - YEAR(MAX('FACT TABLE'[entry date]) ))
average seniority for only the active employees =
AVERAGEX(FILTER(ALLSELECTED('FACT TABLE'),'FACT TABLE'[work]="yes"),[datediff])

3. Result:

Use [Year] of the Date table as the slicer.

When [work]=”no”, it means that it has left the company and does not need to change with the slicer

When [work]=”yes”, it means that there is no resignation, and it changes with the slicer

vyangliumsft_2-1648103712187.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you so much 😁

lkalawski
Memorable Member
Memorable Member

Hi @Mannai ,

 

By having these values:

lkalawski_0-1647861039736.png

you can check active employees based on the end date (or based on the flag) and use this measure to calculate average seniority:

Avg Seniority = CALCULATE(AVERAGE(Employee[Seniority]),Employee[End Date] = BLANK())

 

thank you for the answer but what if i want to see the average in the past where the employee still active ?

 

@Mannai ,

In this case, you need to use a calendar that will help you calculate the Average for the selected month (period). In that case, a better option is to have a measure instead of calculated columns.

Please send me a piece of data so I can write a measure.

Mannai_0-1647960701135.png

this column contain the seniority of each employee until the date of the extract of data
is it possible to have this column dynamically for example :
if john have NOW15 years experience , if i change the date to 2021 i get only 14 years 
i hope you undrestand what i meant


Thank you for your Help

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.