Forum Discussion
Tables are fantastic but cumulative totals are a pain
Hi, PeterBartholomew1 and @Wyn Hopkins!
Could you please explain the steps in more detail?
When I try to set the name prior as referring to =Sheet1!R[-1], I get an error message saying that the formula is not valid.
I tried =Sheet1!R[-1]C but I got the same error.
If I set up the name by selecting A2 and referring to A1 (no dollar sign), the formula is accepted. But I cannot get it to work with the table field names as prior [balance]. It will only work if I use the name alone (no table field associated) to refer to the previous row on the same column.
Any clarification/help would be very much appreciated.
Thanks! :)
I rarely, if ever, use a direct cell reference, so it makes little difference to me whether my workbook is set to the familiar A1 notation or the earlier R1C1 notation. Why I chose to use it here is that it is less ambiguous. If your calculation is set to R1C1,
=Sheet1!R[-1]
is a formula that references the entire row immediately above the active cell with the formula. If you switch to A1 notation, the reference will need to be defined as
=Sheet1!9:9 if the active cell is in row 10
=Sheet1!10:10 if the active cell is in row 11
etc.
This definition (with an adjective used as a name) is made with an eye on generating readable formulas, e.g.
= prior [balance]
is the intersection of the row above the formula and the [balance] column (any two range references separated by a space will return the intersection). Since the row prior intersects all of the columns of the table, one could also use
=(prior [date])
to give the date of the previous transactions.
If your workbook is sufficiently small that you can afford to use volatile functions, then you could, as an alternative, define 'prior' by the formula
=OFFSET(Table1[@],-1,0)
i.e. the table row above the current one. Sample formulas might include the following
= IF( ISREF(prior Table1[#Headers]), "", [@Date] - (prior [Date]) )
for the interval between two transactions (could be of relevance if you are fortunate enough to accrue interest on current balances) or
= IF( ISREF(prior Table1[#Headers]), BFwd, [@Amount] + (prior [Balance]) )
for a running balance. Here the first row will be characterised by the range 'prior' coinciding with the [#Headers] row so, instead of generating an error, the formula will reference the 'balance brought forward'.
Will your colleagues be able to read your formulas? They will be able to deduce the intent but they would run a mile if you suggested they should take responsibility for the workbook!
- Sam_3026Jun 26, 2019Copper Contributor
need help.
we have inventory movement table for various stock items with stock In and Out information.
I am try to create a pivot report, where we can new fields to table such as opening balance, running balance and closing balance for any given point in a time.
can someone help, how to write a formula for opening balance, running balance and closing balance.
see attached spreadsheet for example
- PeterBartholomew1Jun 27, 2019Silver Contributor
Unless Wyn Hopkins wishes your question to be dealt with here, I suggest you open a new thread.
I would also observe that since there are some of the most competent Excel practitioners worldwide responding to this thread it would be a mistake to narrow your potential solutions to a specific approach.
- Wyn HopkinsJun 27, 2019MVP
Hi Sam_3026 ,
Yes if you could just post a new item to the community about this that would be great.
@ us in if you like
Cheers
Wyn