Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to subtract the last non-empty cell in Numbers?

Hi all,


I'm stumped on what seems like a simple issue.


I have a numbers sheet where electrical meter usage is entered

This isn't done every day, but usually at least weekly.


Date | Reading | Difference

1/1/19 | 12300 | - (First entry of the month is always blank)

1/2/19 | |

...

1/5/19 | 12345 | 45


This is being moved from Excel to Numbers due to some issues with Office 365.

The excel formula that worked is:

IF(B11=0,"",B11−LOOKUP(2,1÷(B10≠0),B10))


I'm also doing the work now on a macbook, but I expect this will mostly be used on an iPad once I get the formula working properly.


Any suggestions on how to get this working with Numbers?


Thanks!

Macbook (2016 or later)

Posted on Jan 13, 2019 10:52 AM

Reply
Question marked as Best reply

Posted on Jan 14, 2019 1:07 AM

Hi JB,


Restating your specifications:


Readings are recorded chronologically in column B.

Some rows will not contain a reading.

The reading shown furthest down the table will be the maximum value in column B.

When a new reading is added in a row below it, the most revent previous reading will be the previous maximum, and the new reding will become the maximum.

If there is a reading recorded on 'this row', you want to subtract the previous maximum from the current reading, and place the result in 'this row' of column C.

If there is no reading recorded on 'this row', you want the cell in 'this row of column C to appear empty.


Here's an example that should provide the result you are looking for:


The formula shown is entered in C3, then filled down to the end of column C.


C3: IF(LEN(B3)<1,"",MAX(B$2:B3)−MAX(B$2:B2))


The part shown in bold does the calculation, subtracting the maximum value in cells above 'this row' from the current maximum value (in 'this row').

The part in normal type weight checks for an entry in 'this row' of column B, and prevents the calculation if an entry is not found.


Regards,

Barry


5 replies
Question marked as Best reply

Jan 14, 2019 1:07 AM in response to JBSpinks

Hi JB,


Restating your specifications:


Readings are recorded chronologically in column B.

Some rows will not contain a reading.

The reading shown furthest down the table will be the maximum value in column B.

When a new reading is added in a row below it, the most revent previous reading will be the previous maximum, and the new reding will become the maximum.

If there is a reading recorded on 'this row', you want to subtract the previous maximum from the current reading, and place the result in 'this row' of column C.

If there is no reading recorded on 'this row', you want the cell in 'this row of column C to appear empty.


Here's an example that should provide the result you are looking for:


The formula shown is entered in C3, then filled down to the end of column C.


C3: IF(LEN(B3)<1,"",MAX(B$2:B3)−MAX(B$2:B2))


The part shown in bold does the calculation, subtracting the maximum value in cells above 'this row' from the current maximum value (in 'this row').

The part in normal type weight checks for an entry in 'this row' of column B, and prevents the calculation if an entry is not found.


Regards,

Barry


Jan 13, 2019 11:56 AM in response to jaxjason

Jason,


Thanks for the tip.


With that suggestion, wouldn't the result be 0 if I am subtracting the Max value?

As you mention the numbers always go up, so the data I enter today will be the highest number.

If I record today's data and subtract the column max, result would be 0 unless I exempted the data I just entered somehow. (and there might be a simple answer to that too)


Data is pretty simple -


Column A is date

Column B is Electrical Meter reading

Column C is the Difference from the last meter reading - this is where I will put the formula.


At the bottom of the page I will Sum column C to get a total used number for the month (simple sum works here).


Rows are the days in the month:

Jan 1 2019

Jan 2 2019

Jan 3 2019

...


The sheet covers the year with a different tab for each month.


So If I have a Jan 1 reading of 12300 (made up number) I won't have a difference since that is how I start the month.

On the first reading after Jan 1 I will subtract the new reading from the Jan 1 number.


If I don't record the number again until Jan 5, I want to subtract the Jan5 number from the Jan 1 number to get the difference.

I'm required to list all days on the sheet even if I don't have a reading, so I need to ignore the empty cells and read the last cell in the column with a value.

As you mention the numbers should always increase in the readings.


Hopefully that makes this example make more sense...


Date | Reading | Difference

Jan 1 2019 | 12300

Jan 2 2019

Jan 3 2019

Jan 4 2019

Jan 5 2019 | 12345 | 45

Jan 6 2019

Jan 7 2019 | 12385 | 40


Thanks for any help.



Jan 13, 2019 3:45 PM in response to JBSpinks

that's what I was trying to figure out with your question. I didn't understand the reason to do it, so I just answered the max.

You state in your title you want to subtract the last non-empty cell, which is the dates increase going down on the table, the last non empty is always the max.


in your most recent response you state "I will subtract the new reading from the Jan 1 number." but that will give you a negative reading. If you subtract the original reading from the max you get current use.


So if you wanted to see use as of that date you wouldn't need to find the max, that lines number was the max that day. Just use absolute referencing to lock the initial value.

So if B1 had the original value for the month, and you are on any cell beneath that with a value for some date, you would enter this as a formula


=B2-B$1


this could be filled down and it will subtract the value in C1 from the current rows value.


Jason


How to subtract the last non-empty cell in Numbers?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.