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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
eloomis
Advocate II
Advocate II

Calculate the number of weeks a task is active

I have data that looks like this:

 

Task ID | Task Start Date | Task End Date | Task Budget

123          1/26/23                2/10/23           2

 

I want to write a measure to calculate how many weeks the task crosses so that I can multiply the task budget by that amount. So the example here the task would cross 3 weeks, so the result would be 6. 

 

The week starts Monday. Even if the task starts on a Friday, that would still be counted as crossing a full week, so from 1/27 to 1/30 would still be 2 weeks. 

 

I am including multiple filters for specific task types so the ultimate solution will be more complex, but I'm not sure how to accomplish this piece first. 

 

Thank you in advance.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @eloomis 

please try

Total Budget =
SUMX (
Tasks,
(
WEEKNUM ( Tasks[Task End Date], 2 ) - WEEKNUM ( Tasks[Task Start Date], 2 ) + 1
) * Tasks[Task Budget]
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @eloomis 

please try

Total Budget =
SUMX (
Tasks,
(
WEEKNUM ( Tasks[Task End Date], 2 ) - WEEKNUM ( Tasks[Task Start Date], 2 ) + 1
) * Tasks[Task Budget]
)

Thank you - this is almost perfect.

 

There is something weird happening where i am getting negative numbers for some. I think it might be in cases where the Start date is in December 2022 and end date is in 2023. Do you have any ideas on how to resolve this?

@eloomis 
Please try

Total Budget =
SUMX (
    Tasks,
    VAR StartWeek =
        WEEKNUM ( Tasks[Task Start Date], 2 )
    VAR EndWeek =
        WEEKNUM ( Tasks[Task End Date], 2 )
    VAR NumOfWeeks =
        IF ( StartWeek > EndWeek, 54 - StartWeek + EndWeek, EndWeek - StartWeek + 1 )
    RETURN
        NumOfWeeks * Tasks[Task Budget]
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors