Running Totals within a calculation

  • I need to create a running total to get the remaining balance but I am having a hard time.

    The columns look like this:

    Total Amount Invoiced Remaining

    10,0000 12000 (2,000)

    1/1/10 9000 1,000

    2/1/10 3000 (2,000)

    I have done this but it does not seem to be pulling correctly:

    = Sum(totalAmount) - (runningvalue(Invoiced, Sum, "Amount")

    Any other ideas?

  • It would be helpful if you could give a bit better explanation of what you are looking for.

    The sample data you provided, is that what you want it to look like or sample data that we can manipulate? We need both so that we can help you with your calculation. Please see the first link in my signature for more information on how to help us help you.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • what I want to do is do the following:

    take the 10000 (total) and subtract it from the detailed amount from lines.

    10000 - 9000 = 1000

    1000- 3000 = -2000

    does that help?

  • so each row is it's own calculation not a running total including the row above it?

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Here is an excellent article by Jeff Moden which might assist you. I suggest you read it, and run the sample code provided

    http://www.sqlservercentral.com/articles/T-SQL/68467/

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • KJ:

    I see what you're trying to do here. You've got a starting sum (or a continuously added to sum) and then negatives in another structure you want both a running total and a final summation.

    We need the physical table structure (DDL) and significant volume of sample data (20+ lines) along with a very specific result set to help you out with this. Please see the first link in my signature to get started.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply