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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

SUM Column if Date is equal to or 6 days greater than another date

Hey community,

 

Dataset 1

Week Commencing DateEarned HoursExpended Hours Productivity (Earned Hours / Expended Hours)
06/01/202310200.5
13/01/20231052

 

Dataset 2

Created DateDifference
07/01/20231
15/01/20232

 

I need to create a measure that reads as follows:

 

(If 'Created Date' is equal or + 6 to 'Week Commencing Date' then SUM difference. + 'Earned Hours') / 'Expended Hours'

 

Can anyone help me with this DAX?

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

Hi , @Anonymous 

According to your description, you want to get the "(If 'Created Date' is equal or + 6 to 'Week Commencing Date' then SUM difference. + 'Earned Hours') / 'Expended Hours'" in datest 2.

In my uderstand , when the [Created Date]=2023/1/7 then we search the [Week Commencing Date]=2023/1/7 or 2023/1/13, then we sum the difference in dateset 2 , this sum of difference is =1  when the [Created Date]=2023/1/7. The 'Earned Hours' in dataset 1 is =10. The  'Expended Hours'" in dataset 1 is =5.

If this , here are the steps you can refer to :My test data is the same as yours.

[1]If you want to add a calculated column in dataset 2 , you can click "New Column" and enter this:

Column =
var _date =  {[Created Date],[Created Date]+6}
var _t = FILTER('Table','Table'[Week Commencing Date] in _date)
return
DIVIDE([Difference] + SUMX(_t ,[Earned Hours]) ,  SUMX(_t ,[Expended Hours ]))

The result is as follows:

vyueyunzhmsft_0-1675308336164.png

[2]If you want to add a measure, you can use this dax code:

Measure = var _cur_createdDate = MAX('Table (2)'[Created Date])
var _date =  {_cur_createdDate,_cur_createdDate+6}
var _t = FILTER('Table','Table'[Week Commencing Date] in _date)
return
DIVIDE(SUM('Table (2)'[Difference]) + SUMX(_t ,[Earned Hours]) ,  SUMX(_t ,[Expended Hours ]))

The result is as follows:

vyueyunzhmsft_1-1675308461980.png

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

Hi , @Anonymous 

According to your description, you want to get the "(If 'Created Date' is equal or + 6 to 'Week Commencing Date' then SUM difference. + 'Earned Hours') / 'Expended Hours'" in datest 2.

In my uderstand , when the [Created Date]=2023/1/7 then we search the [Week Commencing Date]=2023/1/7 or 2023/1/13, then we sum the difference in dateset 2 , this sum of difference is =1  when the [Created Date]=2023/1/7. The 'Earned Hours' in dataset 1 is =10. The  'Expended Hours'" in dataset 1 is =5.

If this , here are the steps you can refer to :My test data is the same as yours.

[1]If you want to add a calculated column in dataset 2 , you can click "New Column" and enter this:

Column =
var _date =  {[Created Date],[Created Date]+6}
var _t = FILTER('Table','Table'[Week Commencing Date] in _date)
return
DIVIDE([Difference] + SUMX(_t ,[Earned Hours]) ,  SUMX(_t ,[Expended Hours ]))

The result is as follows:

vyueyunzhmsft_0-1675308336164.png

[2]If you want to add a measure, you can use this dax code:

Measure = var _cur_createdDate = MAX('Table (2)'[Created Date])
var _date =  {_cur_createdDate,_cur_createdDate+6}
var _t = FILTER('Table','Table'[Week Commencing Date] in _date)
return
DIVIDE(SUM('Table (2)'[Difference]) + SUMX(_t ,[Earned Hours]) ,  SUMX(_t ,[Expended Hours ]))

The result is as follows:

vyueyunzhmsft_1-1675308461980.png

 

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.