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

Calculate SUM of Hours in week

Hello All,

 

I have got a table which has Employee Name, Date and Hours Worked. See data below - 

 

 

DateEmployee NameWeek NumberHours WorkedExpected Result
02/11/2020ABC7234
02/12/2020ABC7234
02/11/2020ABC7334
02/12/2020ABC7334
02/13/2020ABC7834
02/14/2020ABC7834
02/15/2020ABC7834
02/11/2020XYZ7842
02/12/2020XYZ7842
02/13/2020XYZ7842
02/14/2020XYZ7842
02/15/2020XYZ71042

 

So what I would like to do is calculate the hours by ABC in week 7. The week starts on Thursday. So on and so forth.

 

Thanks in Advance.

 

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

Hi @Anonymous ,

 

Try this formula please.

Column = CALCULATE(SUM('Table'[Hours Worked]),FILTER('Table','Table'[Employee Name]=EARLIER('Table'[Employee Name])&&'Table'[Week Number]=EARLIER('Table'[Week Number])))

2.PNG 

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

8 REPLIES 8
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try this formula please.

Column = CALCULATE(SUM('Table'[Hours Worked]),FILTER('Table','Table'[Employee Name]=EARLIER('Table'[Employee Name])&&'Table'[Week Number]=EARLIER('Table'[Week Number])))

2.PNG 

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
az38
Community Champion
Community Champion

Hi @Anonymous 

if I understand you correct you need a measure like

CALCULATE(SUM(Table[Hours Worked]), ALLEXCEPT(Table, Table[Employee Name], Table[Week Number]) )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

@az38 I am not looking to add a measure. I need a calculated column.

az38
Community Champion
Community Champion

@Anonymous 

it will have completely the same formula


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

@az38 I had already tried this solution. It gives incorrect solution.

 

For example, for employee ABC the total hours come out as 40. The answer is same for Column and measure.

Hi @Anonymous,

the measure or formula for the calculated column of @az38 with your sample data is correct:

 

25-06-_2020_00-47-10.jpg

 

Regards FrankAT

 

Anonymous
Not applicable

@FrankAT & @az38  what could affect a different result. 

Let's suppose I have more columns than this and multiple rows are not the same but Employee Name, Week Number is the same. Is that the reason I am not getting the correct result.

az38
Community Champion
Community Champion

@Anonymous 

it shouldn't be as ALLEXCEPT() remove all filters except Employee Name and Week Number

Check your data first.


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.