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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Teddy92
New Member

Count of employees present

Hello,

I have a table with a list of 1500 employees and their arrival date in the company and the depature date if they heave leave the company. I need to present a chart with the number of empoyees present for each month, considering that an employee is present for the month if he has arrived or has left the company during the month.

Teddy92_1-1681421842824.png

Could you help me ?

Thanks you very much for your help.

 

1 ACCEPTED SOLUTION

hi @Teddy92 

1) try to create a calcualed table like:

Dates = 
ADDCOLUMNS(
    CALENDAR(
        MIN(TableName[Arrival date]),
        MAX(MAX(TableName[Arrival date]), MAX(TableName[Departure date]))
    ),
    "YY/MM",
    FORMAT([Date],"YY/MM")
)

 

2) plot a visual with the [YY/MM] column and a measure like:

Measure = 
VAR _month=FORMAT(MAX(dates[date]), "yymm")
RETURN
COUNTROWS(
    FILTER(
        TableName,
        FORMAT(TableName[Arrival Date], "yymm")<=_month
        &&(FORMAT(TableName[Departure Date], "yymm")>=_month || TableName[Departure Date]=BLANK())
    )
)

it worked like:

FreemanZ_0-1681560551342.png

Note: The two tables shall be unrelated. 

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @Teddy92 

You may creat a unrelated date table then plot a chart with the dates[date] and a measure like:
Measure =
VAR _month=FORMAT(MAX(dates[date]), "yymm")
RETURN
COUNTROWS(
    FILTER(
        TableName,
        FORMAT(TableName[ArrivalDate], "yymm")<=_month
        &&(FORMAT(TableName[DepartureDate], "yymm")>=_month || TableName[DepartureDate]=BLANK())
    )
)

Thanks  @FreemanZ ,

I have adapted your code to my context, but I have this error for the measure : "the syntax for RETURN is incorrect".

hi @Teddy92 

1) try to create a calcualed table like:

Dates = 
ADDCOLUMNS(
    CALENDAR(
        MIN(TableName[Arrival date]),
        MAX(MAX(TableName[Arrival date]), MAX(TableName[Departure date]))
    ),
    "YY/MM",
    FORMAT([Date],"YY/MM")
)

 

2) plot a visual with the [YY/MM] column and a measure like:

Measure = 
VAR _month=FORMAT(MAX(dates[date]), "yymm")
RETURN
COUNTROWS(
    FILTER(
        TableName,
        FORMAT(TableName[Arrival Date], "yymm")<=_month
        &&(FORMAT(TableName[Departure Date], "yymm")>=_month || TableName[Departure Date]=BLANK())
    )
)

it worked like:

FreemanZ_0-1681560551342.png

Note: The two tables shall be unrelated. 

Hello @FreemanZ 

Thank you very much for this solution. I have understood my mistake.

I am a beginner in powerBi and DAX.

I have just a last problem : the YY/MM are ordered by the number of employees and not by the real time. Where can I change the parameter ?

Thanks for your help.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.