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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
david148
Frequent Visitor

Count Active Agents Between Two Dates

Hi there,

 

I am working on Power BI to create a report on Agent Staffing at my work. The formula I am trying to wrap my head around is to calculate the total number of Active agents on a particular date.

 

This is very easy to do in Excel as shown in the table below I have 5 agents listed with varied Start and End Dates. (31/12/9999 used to show that there is no end date confirmed)

Capture1.PNG

And on another table I can run a simple COUNTIFS formula to work out how many of these agents were Active on a particular date as shown below.

Capture2.PNG

 

The trouble I have is in Power BI I need to replicate this, and I need a Date Range that dynamically updates according to the Dates on the RAW data. For this I set myself up a CALENDARAUTO for these dates. But I am having trouble linking these two tables.

 

Therefore my questions are as follows.

  1. What would be the best approach to linking these two tables?
  2. Once linked what formula would you suggest using to calculate the total number of agents who are active on a day on the Calendar table.

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @david148 

no need to have the 2nd table

First create a date table

Date =
CALENDAR ( MIN ( Table[Start Date] ), MAX ( Table[End Date] ) )
Active =
VAR SelectedDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUMX (
            Table,
            IF (
                Table[Start Date] <= SelectedDate
                    && Table[End Date] >= SelectedDate,
                1,
                0
            )
        ),
        'Date'[Date] <= SelectedDate
    )

then create a measure 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @david148 

no need to have the 2nd table

First create a date table

Date =
CALENDAR ( MIN ( Table[Start Date] ), MAX ( Table[End Date] ) )
Active =
VAR SelectedDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUMX (
            Table,
            IF (
                Table[Start Date] <= SelectedDate
                    && Table[End Date] >= SelectedDate,
                1,
                0
            )
        ),
        'Date'[Date] <= SelectedDate
    )

then create a measure 

Thank you so much. That did it 🙂

@david148 
Wht do you think now, which is easier? DAX or EXCEL?

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors