简体   繁体   中英

Get max change between rows, ignoring empty cells at end of list

I have a spreadsheet where I'm tracking my net worth over time. Once a month, I add in my account balances.

In one sheet, I have this structure:

Date Year Net Worth Account1 Account2 Account3
Jan 31, 2021 2021 $320 $200 $140 -$20
Feb 28, 2021 2021 $340 $200 $150 -$10
Mar 31, 2021 2021 $410 $250 $200 -$40
Apr 30, 2021
May 31, 2021

...rest of months for the year

The formula in the Year column is =if(C3<>"", year(A3), "") .

The formula in the Net worth column is =if(sum(D3:F3)<>0, sum(D3:F3), "") .

The Problem: I'd like to have a cell which lists the greatest 1 month change (so $410 - $340 = $70), without having to update the formula every month. (In an ideal world, I never need to touch it again, only ever having to enter account balances once a month.)

What I've got so far:

=if(
  abs(min(ArrayFormula(C3:C400 - C2:C399)))=max(ArrayFormula(abs(C3:C400 - C2:C399))), 
  min(ArrayFormula(C3:C400 - C2:C399)),
  max(ArrayFormula(C3:C400 - C2:C399))
)

However, this includes the change from $410 to "" , which is coerced to $0. So instead of the expected $70, I'm instead getting $410.

How can I get the greatest 1 month change, but ignore the empty string values?

Easiest way to fix it is just to put in an if clause I think:

=ArrayFormula(max(if(C3:C400<>"",abs(C3:C400-C2:C399),)))

because Max will ignore the empty string generated by the If statement

or slightly shorter:

=ArrayFormula(max((C3:C400<>"")*abs(C3:C400-C2:C399)))

so that the change for any empty cells is set to zero.

These assume that C2 itself is not blank!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM