Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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 ...
  • Anonymous's avatar
    Anonymous
    8 years ago

     

    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
    	)	
    )