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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
deevo
Helper I
Helper I

Staff availability between 2 dates - modification to measure required

Hi all,

I have attached a sample pbix link with very small dataset, but in reality my dataset has about 3 million rows (Please keep this in mind when writing the DAX formula).

Link: https://drive.google.com/file/d/1oBLZyqJ1M3R6qLSrw4oMCXwGyg9-5Vln/view?usp=drive_link

I need some help with modifying my current measure to SUM together the "Assignment (hrs)" for each row with an "Assignment Start Date" and "Assignment Finish Date". If the "Assignment Start Date" and "Assignment Finish Date" overlap with multiple Assignments, then all these Assignments should be added together to get a grand total of assignments within that date range and used in the measure below:

 

Assignment Period Availability between Assign Start and End dates (hrs) =
CALCULATE(
    [Capacity (hrs)] - [Assignments (hrs)],
    FILTER (
        'Dim Date FY24-25',
        'Dim Date FY24-25'[Date] >= MIN('Data 2 - Staff Assignments By Day'[Assignment Start Date]) && 'Dim Date FY24-25'[Date] <= MAX('Data 2 - Staff Assignments By Day'[Assignment Finish Date])
    ))
 
Below is a sscreenshot from my PBIX file:
deevo_0-1736947424738.png

Please see the PBIX file, i have laid it all out in there for you to play around with. Thanks!

4 REPLIES 4
deevo
Helper I
Helper I

@DataNinja777 

I am still unable to resolve this. Are you available to assist?

If you could provide a fix within the PBIX so I can see what changes you made, that would be very helpful.

Thanks once again

deevo
Helper I
Helper I

This is an amazing explanation. Very easy to understand. I will try it out tomorrow morning with my real dataset and let you know how the performance is. Thank you very much.

DataNinja777
Super User
Super User

Hi @deevo ,

 

To modify your current measure for summing the "Assignment (hrs)" within overlapping assignment periods, we need to ensure the DAX logic efficiently handles large datasets, like your 3-million-row dataset. The objective is to calculate the total assignment hours for any overlapping assignments between the "Assignment Start Date" and "Assignment Finish Date," ensuring that every relevant assignment within that date range is included in the sum.

Here's a refined DAX measure that calculates the Assignment Period Availability by subtracting the overlapping "Assignment (hrs)" from the "Capacity (hrs)". The measure uses variables to define the date range and applies a filtered context to sum all overlapping assignment hours within that range.

Assignment Period Availability between Assign Start and End dates (hrs) =
VAR StartDate = MIN('Data 2 - Staff Assignments By Day'[Assignment Start Date])
VAR EndDate = MAX('Data 2 - Staff Assignments By Day'[Assignment Finish Date])

RETURN
CALCULATE(
    [Capacity (hrs)] - 
    SUMX(
        FILTER(
            'Data 2 - Staff Assignments By Day',
            'Data 2 - Staff Assignments By Day'[Assignment Start Date] <= EndDate &&
            'Data 2 - Staff Assignments By Day'[Assignment Finish Date] >= StartDate
        ),
        'Data 2 - Staff Assignments By Day'[Assignment (hrs)]
    ),
    FILTER(
        'Dim Date FY24-25',
        'Dim Date FY24-25'[Date] >= StartDate &&
        'Dim Date FY24-25'[Date] <= EndDate
    )
)

 

In this measure, we start by defining two variables, StartDate and EndDate, to capture the minimum "Assignment Start Date" and maximum "Assignment Finish Date" from the current row context in the 'Data 2 - Staff Assignments By Day' table. These variables set the boundaries for the date range we want to evaluate. The CALCULATE function is then used to adjust the filter context by applying a SUMX over a filtered subset of the 'Data 2 - Staff Assignments By Day' table. The FILTER inside SUMX identifies rows where the assignment periods overlap with the current date range. Specifically, it checks that the "Assignment Start Date" is before or equal to the EndDate and that the "Assignment Finish Date" is after or equal to the StartDate.

Finally, the outer FILTER on the 'Dim Date FY24-25' table ensures that the measure evaluates only within the desired date range from the calendar table. This approach ensures that overlapping assignments are correctly summed, even when there are multiple assignments within the same time period. The use of variables and efficient filtering helps optimize performance for large datasets by reducing the number of rows evaluated during each calculation.

 

Best regards,

@DataNinja777 

I have applied that formula to my test PBIX (the file in my google drive link), and the result isnt matching the "Expected results".

 

Could it be the date formats between the assignments and dim date dont match?

Could it be that the Dim Date is not being recognised?

 

Thanks in advance!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.