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
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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Super User
Super User

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
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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.