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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
TCatron18
Helper II
Helper II

Sum of Column Based on Date of Another Column

I am needing to pull the sum of hours for an ID into another table for the date ranges that are within the past 12 months of the effective date. 

I've tried several different DAX formulas without any luck.

I have two tables:

Hours Table

IDHOURSBEGINEND
174.274/20/20255/3/2025
153.674/6/20254/19/2025
183.413/23/20254/5/2025
175.513/9/20253/22/2025
143.932/23/20253/8/2025
133.982/9/20252/22/2025
169.661/26/20252/8/2025
187.481/12/20251/25/2025
172.6812/29/20241/11/2025
140.8712/15/202412/28/2024
161.4712/1/202412/14/2024
157.1911/17/202411/30/2024
191.911/3/202411/16/2024
187.1210/20/202411/2/2024
166.2510/6/202410/19/2024
196.59/22/202410/5/2024
156.259/8/20249/21/2024

 

Data Table

IDEFFECTIVE
14/6/2025

 

I am needing to pull the sum of the hours from the Hours table into the Data table for hours that were within the past 12 months from the effective date in the Data table. 

My data is much larger than provided in the example where the dates in both tables are different for different IDs. 

 

My expected result:

IDEFFECTIVEHOURS
14/6/2025

1024.2

 

Any assistance in getting this achieved would be greatly appreciated.

Thanks!!

1 ACCEPTED SOLUTION
Deku
Super User
Super User

Assuming relationship between id in each table

 

Measure =

Var endDt = selectedvalue( data[effective date])

Var dartDt = datediff( endDt, -12, month )

Return

Sumx(

Filter(

Hours,

hours[begin] <= endDt &&

Hours[end] >= startDt

),

Hours[hours]

)

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

6 REPLIES 6
Deku
Super User
Super User

Assuming relationship between id in each table

 

Measure =

Var endDt = selectedvalue( data[effective date])

Var dartDt = datediff( endDt, -12, month )

Return

Sumx(

Filter(

Hours,

hours[begin] <= endDt &&

Hours[end] >= startDt

),

Hours[hours]

)

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

@Deku I've now run into an error with this setup due to the relationship between the tables where the Data table now has duplicate IDs, so I'm getting an error that there cannot be duplicates in a table where it's on the one side of a many-to-one relationship or used as the key between tables. Do I have any options to resolve this?

You can have a many many relationship and set the filter direction as you previous had


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

@Deku Is the many-to-many relationship something that is in the newer version of PBI? I don't seem to have that option with the May 2021 version. I only have many-to-one, one-to-one, or one-to-many. 

You can use a bridge table like here https://www.sqlbi.com/articles/different-options-to-model-many-to-many-relationships-in-power-bi-and...


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

@Deku Thank you 😁 That works perfectly!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Users online (9,294)