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

Evolution of the number of employees over 5 years

Hello,

I have an employee table with a start date column and an end date column.

I also have a "Year" segment that allows me to filter the report by year.

I would like to have, over the last 5 years of the filter, the evolution of the number of employees of my company.

 

 Can we do this under PowerBI?

 

 Sample data:

ID, StartDate, EndDate

1,2011-01-01, null

2,2012-02-07,2014-01-21
3,2013-03-14,2016-07-11
4,2014-04-23, null
5,2015-05-05,2015-07-14
6,2016-06-09,2019-12-12
7,2017-07-30, null
8,2018-08-21, null
9,2019-09-15, null
10,2020-10-16, null


Expected results :

When Filter on 2015:

- 2011: 1

- 2012: 2

- 2013: 3

- 2014: 4

- 2015: 4

 

When filter on 2020:

- 2016: 4

- 2017: 4

- 2018: 5

- 2019: 6

- 2020: 6

 

Thanks in advance,

-Florent

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi Florent,

 

Please download a demo from the attachment. Is the "Year" in another table? If not, you may need a new table.

Table =
FILTER (
    DISTINCT (
        UNION (
            SELECTCOLUMNS ( 'Table1', "Year", YEAR ( [StartDate] ) ),
            SELECTCOLUMNS ( 'Table1', "Year", YEAR ( [EndDate] ) )
        )
    ),
    ISBLANK ( [Year] ) = FALSE ()
)

Create a measure.

Measure =
VAR selectedYear =
    MIN ( 'Table'[Year] )
VAR rowYear =
    YEAR ( MIN ( 'Table1'[StartDate] ) )
RETURN
    CALCULATE (
        IF (
            rowYear
                > selectedYear - 5
                && rowYear <= selectedYear,
            COUNTX (
                FILTER (
                    ALL ( 'Table1' ),
                    YEAR ( [StartDate] ) <= rowYear
                        && YEAR ( IF ( ISBLANK ( [EndDate] ), DATE ( 9999, 12, 31 ), [EndDate] ) )
                            >= rowYear
                ),
                [ID]
            ),
            BLANK ()
        )
    )

Evolution-of-the-number-of-employees-over-5-years

 

Best Regards,

Community Support Team _ Dale
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

3 REPLIES 3
v-jiascu-msft
Employee
Employee

Hi Florent,

 

Please download a demo from the attachment. Is the "Year" in another table? If not, you may need a new table.

Table =
FILTER (
    DISTINCT (
        UNION (
            SELECTCOLUMNS ( 'Table1', "Year", YEAR ( [StartDate] ) ),
            SELECTCOLUMNS ( 'Table1', "Year", YEAR ( [EndDate] ) )
        )
    ),
    ISBLANK ( [Year] ) = FALSE ()
)

Create a measure.

Measure =
VAR selectedYear =
    MIN ( 'Table'[Year] )
VAR rowYear =
    YEAR ( MIN ( 'Table1'[StartDate] ) )
RETURN
    CALCULATE (
        IF (
            rowYear
                > selectedYear - 5
                && rowYear <= selectedYear,
            COUNTX (
                FILTER (
                    ALL ( 'Table1' ),
                    YEAR ( [StartDate] ) <= rowYear
                        && YEAR ( IF ( ISBLANK ( [EndDate] ), DATE ( 9999, 12, 31 ), [EndDate] ) )
                            >= rowYear
                ),
                [ID]
            ),
            BLANK ()
        )
    )

Evolution-of-the-number-of-employees-over-5-years

 

Best Regards,

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

Thank you !

Your 2 solutions work, but v_jiascu_msft's is a little faster 🙂

 

Regards,

Florent

Greg_Deckler
Super User
Super User

This looks like a date interval sort of situation, I created a couple of Quick Measures to deal with this sort of thing:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364

https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.