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

Analyse Employee Data

Hi,

 

I need some help with my employee data. My table looks like this:

 

nameentryexit
A01.05.201101.06.2013
B01.07.201301.07.2015
C01.01.2017null

 

I want to know, how long (relative to a full year) each employee worked for each year. The result table should look like this:

 

nameyearamount
A20110,66666667
A20121
A20130,41666667
B20130,5
B20141
B20150,5
C20171
C20181
C20191

 

The current year (here: 2019) should always count 1 unless there is an exit date (if the exit date for C was 01.07.2019, the value for C - 2019 would be 0,5).

 

I have no idea how to do it - can anyone help?

 

Thanks so much!

Mark

2 ACCEPTED SOLUTIONS
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

First, you need a new table to save all dates.

Year =
GENERATESERIES ( YEAR ( MIN ( 'Table'[entry] ) ), YEAR ( NOW () ), 1 )

Then cross join two tables to get a new temporary table.

TEMPTABLE =
CROSSJOIN ( 'Table', 'Year' )

Create the final table after filtering.

FinalTable =
CALCULATETABLE (
    'TEMPTABLE',
    FILTER (
        'TEMPTABLE',
        'TEMPTABLE'[Value]
            <= IF ( ISBLANK ( YEAR ( 'TEMPTABLE'[exit] ) ), 2019, YEAR ( 'TEMPTABLE'[exit] ) )
            && 'TEMPTABLE'[Value] >= YEAR ( 'TEMPTABLE'[entry] )
    )
)


5-1.PNG

Now you can create  a column to get your result with your logic.

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

Hi @Anonymous ,

 

The 2019 is the year at which the date ends. I use this hard code to get test result faster. So Year(today()) can work. As for YEAR(LASTDATE('Year'[End])), it is the same as your code to get the year at which the date ends.

 

Best Regards,

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

6 REPLIES 6
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

First, you need a new table to save all dates.

Year =
GENERATESERIES ( YEAR ( MIN ( 'Table'[entry] ) ), YEAR ( NOW () ), 1 )

Then cross join two tables to get a new temporary table.

TEMPTABLE =
CROSSJOIN ( 'Table', 'Year' )

Create the final table after filtering.

FinalTable =
CALCULATETABLE (
    'TEMPTABLE',
    FILTER (
        'TEMPTABLE',
        'TEMPTABLE'[Value]
            <= IF ( ISBLANK ( YEAR ( 'TEMPTABLE'[exit] ) ), 2019, YEAR ( 'TEMPTABLE'[exit] ) )
            && 'TEMPTABLE'[Value] >= YEAR ( 'TEMPTABLE'[entry] )
    )
)


5-1.PNG

Now you can create  a column to get your result with your logic.

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

Hi @v-eachen-msft ,

 

thank you! I think that will be the solution!

 

One question:

You have hard-coded "2019" as the current year. When we go to the next year, this would not be valid any more, right? Can we code that differently?

 

Thanks!

Mark

Hi @Anonymous ,

 

You can use this code:YEAR(LASTDATE('Year'[End])) to replace 2019.
 

Best Regards,

Eads

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

Hi @v-eachen-msft ,

 

I am not sure if that works as it should.

 

I now used Year(today()) to replace 2019, because I always want to make the calculation until the current date. 

 

Can you please tell me again what the "2019" exactly does within the code?

 

Thanks!

Mark

Hi @Anonymous ,

 

The 2019 is the year at which the date ends. I use this hard code to get test result faster. So Year(today()) can work. As for YEAR(LASTDATE('Year'[End])), it is the same as your code to get the year at which the date ends.

 

Best Regards,

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

I want to explain again, what the goal here is:

 

In the end there should be a chart which shows how many employees there are working for each year. 

And from my point of view there is now way to archive this with the first table, right?

 

Maybe that helps!

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.