Monday, March 26, 2012

Running Total: Summing on Distinct Amount

I am trying to do a sum on a goal amount that is repeated for each record. But what is the the forumla to only sum on the distinct goal amount.

Example:

Month Year Goal Other Value

March 2007 500 5568

March 2007 500 5568

March 2007 500 5569

April 2007 600 5568

April 2007 700 5569

Total (I am receive)

March-April 2007 1600 5568

March-April 2007 1200 5569

Total (I excpect)

March-April 2007 1100 5568

March-April 2007 1200 5569

I haven't found anything online to help.

Thanks,

Sam

You could define you data set using the following SQL.

SELECT Month, Year, [Other Value], SUM(Goal)

FROM (

SELECT DISTINCT Month, Year, [Other Value], Goal

FROM TableName

)

GROUP BY Month, Year, [Other Value]

|||

I actually have more data being returned than what is being displayed in my example. I am already doing a group by in data set. Thanks for the thought.

Sam

|||

I hope this example is better:

Example:

Month Year Goal SalesID ActualSales

March 2007 500 5568 550

March 2007 500 5568 475

March 2007 500 5569 605

April 2007 600 5568 700

April 2007 700 5569 710

No comments:

Post a Comment