cancel
Showing results for
Did you mean:
Highlighted
jarodjp42 Regular Visitor

SUM value by category

I am trying to take the following data and calculate the values for each person.

 person sales Average Jerry 30 10 Jerry 30 10 Jerry 30 10 Tom 25 12.5 Tom 25 12.5 James 20 10 James 20 10 Joe 25 25

I am looking to take the total sales for each person and create a new column (average) that will average the total sales and break it out for each line. Can someone explain how this can be done? Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions Super User

Re: SUM value by category

I don't agree that this is the right way to do this, using measures you can calculate this information display it without needing to store the value on every single line in your data set (which is what a calculated column will do).  Never the less, this is the calculated column code to do what you are asking:

This will produce your calculated column for sales

```Total Sales = var thisPerson = [person]
RETURN
CALCULATE(
SUM('YourTable'[sales])
ALL('YourTable'),
'YourTable'[person] = thisPerson
)```

This calculates the average

```Total Average = var thisPerson = [person]
RETURN
DIVIDE(
[Total Sales],
CALCULATE(
COUNTROWS('YourTable')
ALL('YourTable'),
'YourTable'[person] = thisPerson
)
)```

Proud to be a Datanaut!

2 REPLIES 2 Super User

Re: SUM value by category

I don't agree that this is the right way to do this, using measures you can calculate this information display it without needing to store the value on every single line in your data set (which is what a calculated column will do).  Never the less, this is the calculated column code to do what you are asking:

This will produce your calculated column for sales

```Total Sales = var thisPerson = [person]
RETURN
CALCULATE(
SUM('YourTable'[sales])
ALL('YourTable'),
'YourTable'[person] = thisPerson
)```

This calculates the average

```Total Average = var thisPerson = [person]
RETURN
DIVIDE(
[Total Sales],
CALCULATE(
COUNTROWS('YourTable')
ALL('YourTable'),
'YourTable'[person] = thisPerson
)
)```

Proud to be a Datanaut! Community Support Team

Hi @jarodjp42,