## Desktop

Established Member
Posts: 287
Registered: ‎02-14-2017

# Need help to calculate Average

I am trying to calculate the average of each employees time spend hours.

Sample data:-

 Emp ID begin_date SpendHrs 123 4/2/2018 0:00 8.28 123 4/3/2018 0:00 9.55 123 4/4/2018 0:00 8.19 123 4/5/2018 0:00 8.44 123 4/6/2018 0:00 10.09 123 4/9/2018 0:00 9.58 123 4/10/2018 0:00 9.41 123 4/11/2018 0:00 8.47 123 4/12/2018 0:00 10.38 123 4/13/2018 0:00 10.01 123 4/14/2018 0:00 1.41 123 4/16/2018 0:00 10.01 123 4/17/2018 0:00 9.01

Im using begin date as a slicer to change the date range.

In above image 8.68 is the overall average for that perticular emp id for that perticular date range.

now as date range changes the average also changes.

Now i would like to write a measure or calculated column which will give me the overall average for that percticular date range.

expected output:-

 Emp ID begin_date SpendHrs Avg 123 4/2/2018 0:00 8.28 8.68 123 4/3/2018 0:00 9.55 8.68 123 4/4/2018 0:00 8.19 8.68 123 4/5/2018 0:00 8.44 8.68 123 4/6/2018 0:00 10.09 8.68 123 4/9/2018 0:00 9.58 8.68 123 4/10/2018 0:00 9.41 8.68 123 4/11/2018 0:00 8.47 8.68 123 4/12/2018 0:00 10.38 8.68 123 4/13/2018 0:00 10.01 8.68 123 4/14/2018 0:00 1.41 8.68 123 4/16/2018 0:00 10.01 8.68 123 4/17/2018 0:00 9.01 8.68 Avg = 8.68

How can i get this done.

thanks,

Mohan V

Accepted Solutions
Highlighted
Moderator
Posts: 9,944
Registered: ‎03-10-2016

## Re: Need help to calculate Average

@MohanV,

Create a measure instead of calculated column.

Regards,
Lydia

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

All Replies
Super User
Posts: 1,627
Registered: ‎07-03-2015

## Re: Need help to calculate Average

I’m. It 100% clear what you want, but it sounds like you want this

=calculate(average(table[hours]),All(table[date]))

Or possibly

=calculate(average(table[hours]),Allselected(table[date]))

* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
Established Member
Posts: 287
Registered: ‎02-14-2017

## Re: Need help to calculate Average

i tried what you have suggested.

i have written calculated column for the both functions.

below are the outputs that  i have got.

`_Avg = calculate(average('table'[SpendHrs]),ALLSELECTED('table'[begin_date]))`

`_Avgcolumn = calculate(average('Table'[SpendHrs]),ALL('Table'[begin_date]))`

Highlighted
Moderator
Posts: 9,944
Registered: ‎03-10-2016

## Re: Need help to calculate Average

@MohanV,

Create a measure instead of calculated column.

Regards,
Lydia

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