Forum Discussion

chillpill's avatar
chillpill
Icon for Helper III rankHelper III
2 months ago
Solved

Counting Active employees per month

I would like to count the active headcount for each month but I seem to be running into a road block with the following formula. The fact table (sample below) does not have an active relationship with the calendar table. It is not counting the rows for each month, per Platform, and instead is counting the total # of rows based on the first set of filter criteria in the CALCULATE function but I do not understand why.

Active Count = 
VAR LastDateInPeriod = MAX('Calendar Table'[Date])
VAR FirstDateInPeriod = MIN('Calendar Table'[Date])
RETURN
CALCULATE(
    COUNTROWS('Worker Table'),
    'Worker Table'[Worker] = "CTE",
    'Worker Table'[Record Type] IN {
        "Keep Active",
        "Release - Starting Count",
        "Conv RBG - CTE Starting Count"
        },
    FILTER(
        'Worker Table',
        'Worker Table'[Worker Start Date] <= LastDateInPeriod 
            && OR('Worker Table'[Worker End Date] >= FirstDateInPeriod,ISBLANK('Worker Table'[Worker End Date]))
    )
)

 

Sample table data (not representative of the full table, but so you know the structure):

PlatformIDWorker Start DateWorker End DateWorkerRecord Type
Platform1ID112/01/202504/01/2026CTERelease - Starting Count
Platform1ID211/12/202504/10/2026CTERelease - Starting Count
Platform1ID302/24/202604/17/2026CTERelease - Starting Count
Platform1ID410/22/202504/30/2026CTERelease - Starting Count
Platform1ID510/15/202504/30/2026CTERelease - Starting Count
Platform1ID612/11/202504/30/2026CTERelease - Starting Count
Platform1ID702/07/202405/31/2026CTERelease - Starting Count
Platform1ID6708/04/202508/01/2026CTEConv RBG - CTE Starting Count
Platform1ID14409/01/202510/01/2026CTEConv RBG - CTE Starting Count
Platform1ID27203/27/2023 CTEKeep Active
Platform1ID27305/05/2022 CTEKeep Active
Platform1ID27410/23/2024 CTEKeep Active
Platform1ID27503/27/2023 CTEKeep Active
Platform1ID27604/15/2025 CTEKeep Active
Platform1ID27705/29/2025 CTEKeep Active
Platform1ID27810/29/2024 CTEKeep Active
Platform2ID27903/08/2023 CTEKeep Active
Platform2ID28010/08/202504/30/2026CTERelease - Starting Count
Platform2ID28101/28/2026 CTEKeep Active
Platform2ID28210/20/202512/01/2026CTEConv RBG - CTE Starting Count
Platform2ID28311/10/202506/30/2026CTERelease - Starting Count
Platform2ID28411/03/2025 CTEKeep Active
Platform2ID28507/21/202506/30/2026CTERelease - Starting Count
Platform2ID28612/01/202512/01/2026CTEConv RBG - CTE Starting Count
Platform2ID28711/10/2025 CTEKeep Active

 

When I select a specific Platform it gives me a smaller number (total rows) but isn't filtering down to the Platform specifically for each month:

 

 

  • Hi chillpill,
    Thank you for posting your query in the Microsoft Fabric Community Forum.

    I reproduced your scenario in Power BI Desktop using the sample data provided in the thread and was able to achieve the expected active headcount results by month and by Platform.

    For my testing, I used a disconnected Calendar table and the following measure:

    Active Count =
    
    VAR LastDateInPeriod =
    
        MAX ( 'Calendar Table'[Date] )
    
    VAR FirstDateInPeriod =
    
        MIN ( 'Calendar Table'[Date] )
    
    RETURN
    
    CALCULATE (
    
        COUNTROWS ( 'Worker Table' ),
    
        'Worker Table'[Worker] = "CTE",
    
        'Worker Table'[Record Type]
    
            IN {
    
                "Keep Active",
    
                "Release - Starting Count",
    
                "Conv RBG - CTE Starting Count"
    
            },
    
        FILTER (
    
            'Worker Table',
    
            'Worker Table'[Worker Start Date] <= LastDateInPeriod
    
                &&
    
                (
    
                    ISBLANK ( 'Worker Table'[Worker End Date] )
    
                    || 'Worker Table'[Worker End Date] >= FirstDateInPeriod
    
                )
    
        )
    
    )

    The resulting headcount varied correctly across months and platforms based on the worker start/end dates, which aligns with the requirement of counting employees who were active during the selected month.

    For reference, I have attached the PBIX file that I used to reproduce the scenario.

    Could you please compare it with your model and confirm:

    • Whether the Month field in your matrix comes from the Calendar table.
    • Whether your Calendar table contains one row per day.
    • Whether there are any active/inactive relationships between the Calendar table and Worker table.
    • Whether the values shown in your visual are coming from this measure.

    This information will help identify any model-specific differences that may be affecting the results in your environment.


    Best regards,
    Ganesh Singamshetty

5 Replies

  • Hi chillpill 

    Ensure the relationship between Calendar Table (Dim) and Worker Table (Fact) based on 'Date' column to slice from the Month (from Calendar Table) Slicer

    Active Headcount =
    VAR LastDateInPeriod = MAX ('Calendar Table'[Date])
    VAR WorkerFilter =
    'Worker Table'[Worker] = "CTE" &&

    'Worker Table'[Record Type] IN {"Keep Active", "Release - Starting Count", "Conv RBG - CTE Starting Count"}
    VAR ActiveCondition =
    'Worker Table'[Worker Start Date] <= LastDateInPeriod &&

    (ISBLANK('Worker Table'[Worker End Date]) ||

    'Worker Table'[Worker End Date] >= LastDateInPeriod)
    RETURN
    CALCULATE (COUNTROWS('Worker Table'),
    KEEPFILTERS (WorkerFilter),
    FILTER (ALL('Worker Table'), ActiveCondition))

    • chillpill's avatar
      chillpill
      Icon for Helper III rankHelper III

      Hi there, thanks for the help. There is no 'Date' column in the fact table since this is based on worker start and end date, unless you are recommending they be connected to either start date or end date columns?

  • Hello, chillpill 

    Could you please provide the expected output of the sample data you have provided.
    because based on your current DAX there is no relationship with the datetable so it not provide context based output.
    -> Firstly you must have to create a relationship between one of the column of date and then based on that you can get the output.

    -> and in which way you want to handle the blank value is also mattered.

    -> If you could provide the expected output from the sample data then may be we can provide the soulution you want.

    Thank you.

  • v-ssriganesh's avatar
    v-ssriganesh
    Icon for Community Support rankCommunity Support

    Hi chillpill,
    Thank you for posting your query in the Microsoft Fabric Community Forum.

    I reproduced your scenario in Power BI Desktop using the sample data provided in the thread and was able to achieve the expected active headcount results by month and by Platform.

    For my testing, I used a disconnected Calendar table and the following measure:

    Active Count =
    
    VAR LastDateInPeriod =
    
        MAX ( 'Calendar Table'[Date] )
    
    VAR FirstDateInPeriod =
    
        MIN ( 'Calendar Table'[Date] )
    
    RETURN
    
    CALCULATE (
    
        COUNTROWS ( 'Worker Table' ),
    
        'Worker Table'[Worker] = "CTE",
    
        'Worker Table'[Record Type]
    
            IN {
    
                "Keep Active",
    
                "Release - Starting Count",
    
                "Conv RBG - CTE Starting Count"
    
            },
    
        FILTER (
    
            'Worker Table',
    
            'Worker Table'[Worker Start Date] <= LastDateInPeriod
    
                &&
    
                (
    
                    ISBLANK ( 'Worker Table'[Worker End Date] )
    
                    || 'Worker Table'[Worker End Date] >= FirstDateInPeriod
    
                )
    
        )
    
    )

    The resulting headcount varied correctly across months and platforms based on the worker start/end dates, which aligns with the requirement of counting employees who were active during the selected month.

    For reference, I have attached the PBIX file that I used to reproduce the scenario.

    Could you please compare it with your model and confirm:

    • Whether the Month field in your matrix comes from the Calendar table.
    • Whether your Calendar table contains one row per day.
    • Whether there are any active/inactive relationships between the Calendar table and Worker table.
    • Whether the values shown in your visual are coming from this measure.

    This information will help identify any model-specific differences that may be affecting the results in your environment.


    Best regards,
    Ganesh Singamshetty