How do I subtract some values based on the text value of a different column?
I have a spreadsheet that is tracking payments between 2 people. It looks like the following:
I'm looking to subtract the value of the Amount
column from the retrospective persons Left to pay
amount, depending on whos name is picked from the dropdown in the Who paid?
column.
For example - E5
has a value of Jill
. D5
has a value of £500
. Because E5
has Jill
as it's value, I would like the value of D5
to be taken away from Jills left to pay value in cell I5
.
I know I would need to use an IF
formula but I can't quite figure it out. Is anyone able to advise on how this would be done?
You need to have "initial" Left to pay
value stored in some cell and then calculate value like this:
LeftToPay = InitialLeftToPay - SUM(AllPaymentsOfPerson)
Try to not use horizontal tables (Left to pay) it is not how Excel (and others) are meant to be used. I suggest to format your tables (named tables and renamed tables are used) like this:
Then formula in Left to pay
column is
Office 365
=[@[Initial value]]-SUM(Payments[Amount]*(Payments[Who]=[@Who]))
Older versions
Array formula has to be used. Formula above must be confirmed by CTRL+SHIFT+ENTER
How it works:
Payments[Who]=[@Who]
Compares value from Left to pay
table column Who
in same row where formula is with whole column Who
in Payments
table. Result is array (same size as Payments
Who
column) with TRUE/FALSE
values.
If you use TRUE/FALSE
values in numeric calculation they are treated as 0/1
values.
{"Jill","Jack","Jill","","",""}="Jack"
={FALSE,TRUE,FALSE,FALSE,FALSE,FALSE}={0,1,0,0,0,0}
Therefore:
SUM(Payments[Amount]*(Payments[Who]=[@Who])
Is SUM
of Payments
Amount
column values multiplied by result of previous step (treat array with values 1
or 0
).
SUM({250,500,100,0,0,0}*{0,1,0,0,0,0})
=SUM({0,500,0,0,0,0} )=500
And finally this sum of "wanted" Ammount
values is substracted from Initial value
.
=25000-500=24500