Forum Discussion

imy's avatar
imy
Helper I
7 years ago
Solved

Calendar

How can I use the in-built calendar in Power BI to for example calculate the number of employees working in the company per year and month?

  • hi, imy 

    The Headcount table is linked to the Date table by the Hiredate Many to one.

    You couldn't link it to date table.

    here are two ways for you refer to:

    1. Use this formula to add a measure directly.

    Count of Active Employee = 
    VAR currentDate =
        MAX ( 'Date'[Date] )
    RETURN
        CALCULATE (
            COUNTROWS ( Headcount ),
            FILTER (
                Headcount,
                ( Headcount[Hire Date] <= currentDate
                    && Headcount[Today] >= currentDate )
               
            )
        )

    Then drag date column from date table and this measure into a bar chart

     

    2. Use this formula create a new table

    Table = FILTER(CROSSJOIN(Headcount,'Date'),'Date'[Date]>=Headcount[Hire Date]&&'Date'[Date]<=Headcount[Today])

    Then create a measure by this formula

    countHeader = CALCULATE(DISTINCTCOUNT('Table'[Name]))

    Now drag Date field from this new table and the measure into a bar chart.

    Result:

    and here is sample pbix file, please try it,

     

    Best Regards,

    Lin

     

     

6 Replies