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
Anonymous
Not applicable

How to iterate through rows of a related table and perform a conditional operation?

I have 2 tables:

 

Projects:

PRStartDateEndDateDailyHours
000101/01/202210/02/20226
000202/01/202202/01/20224

Workload:

DateWorkload in hours
01/01/2022

? (should be 6)

02/01/2022

? (should be 10 since 6+4)

03/01/2022

? (should be 6)

 

How can I calculate the sum of the hours of all the projects that will be active in the specified date? In python code, this would be something like:

 

 

foreach date in workload:
    foreach pr in prTable:
        if (myDate is between pr dates):
            dateWorkload += pr[DailyHours]

 


However, I can't use Python for this purpose. How can I do it in DAX?

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try:

Workload in hours = SUMX(FILTER('Projects',[StartDate]<=EARLIER('Workload'[Date])&&[EndDate]>=EARLIER('Workload'[Date])),[DailyHours])

Final output:

vjianbolimsft_0-1662714057177.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try:

Workload in hours = SUMX(FILTER('Projects',[StartDate]<=EARLIER('Workload'[Date])&&[EndDate]>=EARLIER('Workload'[Date])),[DailyHours])

Final output:

vjianbolimsft_0-1662714057177.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

There is a problem with this. It seems to work just fine, but when I use it in a line graphic, filtering by PR won't change the data displayed. They are not directly related, I don't know if that might be the reason.

Anonymous
Not applicable

Isn't creating a new table with all that data a big performance problem? I have 2000+ projects that can last a few months each.

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.