Substract a cell (if it has a # value) with rows below it in a different column if the conditions are the same - excel

I'm using this equation =IF(K2=0,0, K2-I2) to show the difference in a cell with what a client has to pay vs what he has paid (negative if he paid less than what he had to and positive if he paid more). How would I modify this equation to substract from the next amount paid (k3 in this case) or the following (k4) if they didn't pay in k3 so the difference becomes 0 if its used with the added condition that the name at Column C matches.
The first column is the amount someone needs to pay, the second is what they paid, the fourth shows the difference and the fifth states what it is. I would like the difference from the first row to use the paid amount from the second row to substract from it before applying itself to the difference in the second row. Is this possible? I've tried looking for hours in google with no luck.
Edit:
This is how I would like it to look (this is manually inputting the data). The amount the client has to pay each month is 425.65 so the second month he pays 400 it would first cancel the first 'debt' to then count towards his second month payment which results in more debt than the first pay cycle.

Prelim
Worksheet here / screenshot below refer.
If you don't mind using a 'helper' column (I don't see any other way around this, unless you go down the 'VBA/Pivot' route, given the nature of the sum function re arrays) - then this should (I think!:) address the issue...
Eqns
Helper
=IF(OR(B3<>B4,SUM(D$3:D3*(B$3:B3=B3))>=INDEX($C$3:$C$11,MATCH(B3,$B$3:$B$11,0))),1,0)
This turns 1 when the sum of "Paid" is at least >= "Owing" for the same individual. Assumes: rows ordered chronologically, grouped by 'Person' attribute.
Net ultimate
=IF(B3=B2,"",SUM(D3:INDEX($D$3:$D$11,MATCH(B3&1,$B$3:$B$11&$E$3:$E$11,0))))
Screenshots
This sums from the first instance of 'Paid' for a given Person, to the Paid value corresponding to the first instance of a '1' in the Helper column.
Examples
In this case, A owes £1k at outset, pays £450 initially, then pays a further £700 (i.e. has overpaid by £150). As such, the 'Net ultimate' figure reports back £1,150 (=£450 + £700); it doesn't consider the £50 (did you want it to? If so the function becomes a lot easier, and reduces to a regular sumifs...).
For B: net ultimate = £1,025 (the total amounts paid never exceed what is owing, so tally all amounts paid by B)
Same goes for £1k and C....

Related

Excel formula to find a number within a range of numbers and return a date

First time writing one of these, so I will try and explain what I'm trying to do in an understandable manner.
I'm trying to create a spreadsheet to track when a premium bond wins, and have it return the date that the winning premium bond was purchased. Because premium bonds cannot be purchased singularly, when you buy them your bond numbers are given to you a range (eg: 111AA111111- 111AA111210).
As this is the data they provide, I've set my spreadsheet up with purchase date in column A, first number of the range in column B, and last number of the range in column C.
Sample image of the sheet with example bond ranges and purchase date:
Now on a separate sheet I've listed the wins, with win date in A, winning bond number in B, and prize amount in C. In D or E I would like to somehow get it to then give me from the first sheet the date of purchase that winning bond was from.
Sample image of the sheet with winning bond numbers and month they won:
I've done a lot of googling and found similar threads to do this, but none of them have been quite what I want and I've not yet been able to work out how to tweak them into doing it. These have used index and sumproduct, but I'm yet to get it to work.
Any help in the right direction is greatly appreciated. If this doesn't make sense let me know and I'll try and explain it better.
So, like this:
INDEX($B$3:$B$5,MATCH(C9,$C$3:$C$5,1))
Not added a constraint to limit to the upper value, but you could.
This answer is pretty much the same than #SolarMike's answer but based on a diferent point of view.
If the pattern is always like 111AA111111 where 1 is a numeric value and AA is a text value and unique then you can extract the text part from each id using function MID and search for it with INDEX and MATCH:
Formula is:
=INDEX($A$1:$A$3;MATCH("*"&MID(B9;4;2)&"*";$B$1:$B$3;0))
But for this to work each AA must be unique.

How can I use Excel to calculate the avarage price of some BUY\SELL operation including the sell operations weighs?

I am not so into Excel and I have the following problem.
I have a table like this:
Basiscally it is an example of sheet to keep track of buyed and selled cryptocoin. It does some calculation. The column title are in italian so following some details:
B column: it is the operation: BUY or SELL.
D column: the amount of money in EUR (€) related this buy or sell operation.
E column: the price of a single coin in EUR.
F column: the number of coin buyed\selled in this operation.
Then Into the I4 cell I have put the average purchase price calculated by this formula:
=SUM(FILTER(D1:D150;B1:B150="BUY"))/SUM(FILTER(F1:F150;B1:B150="BUY"))
Basically it calculate the avarange purchase price in a simplified way (and not totally correct): it calculate the sum of the total purchase price in EUR (only the BUY operation) dividing it for the sum of the purchased coins (also here only the buyed operation).
I think that this formula is not totally correct because for example the line 4 represents an operation where all my coins was tottally sold, so after the next buy operation (line 5) the new average purchase price (in EUR) should be the eur price of this operation (that after a complete sale can be considered the only operation) for the number of coin related this operation. Basically in this specific case (but this is not a general case) the D5 / F5 that infact have the value of the E5 cell.
Basically I think that the previous formula (defined into I4) should take in consideration also how much does the average purchase price weigh after each sale operation (this because after that a specific number of coins were sold --> the purchase price untill now is the same but when I have another buy operation it must be considered that are less coins).
So basically I was thinking to use this G column containing a value representing the amount of coins updated after each sale, so basically I can have 2 possibility:
There are no previous sell operation (not previous row related a SELL operation in the B column) --> the value will be the sum of the current F value and of the F value of all the previous rows.
There are at least one row before the current one representing a SELL operation --> the value will be the summ of all the F values relatd to all the BUY operation - the sum of all the F values related to all the SELL operation.
I am not sure that this is the best way to procede. Basically what I need in the G cells is the quantity of coin untill this operation (including this operation).
How can I implement this behavior? Or what could be a nice and elegang operation to solve my original problem related my original formula?
This is actually quite a complicated problem…
If you would like to show the running balance of coins, you could do it this way:
=SUMIFS(F:F,B:B,"BUY",C:C,"SHIBA",A:A,"<="&A2:A5)
-SUMIFS(F:F,B:B,"SELL",C:C,"SHIBA",A:A,"<="&A2:A5)
This will calculate your total coin position based on the sum of all purchases prior to today's date, minus the sum of all sales prior to today's date.
However, it's not so straight forward to calculate the average purchase price. When a sale is made, are you looking to deduct it from the oldest purchase first?
Sorry that it's such a messy formula, but here's the formula I came up with:
=LET(
Dates, A2:A5,
DatesRanked, RANK.EQ(Dates,Dates,1),
CumulativePurchases, SUMIFS(F:F,B:B,"BUY",C:C,"SHIBA",A:A,"<="&Dates),
CumulativeSales, TRANSPOSE(SUMIFS(F:F,B:B,"SELL",C:C,"SHIBA",A:A,"<="&Dates)),
RowCount, ROWS(Dates),
Matrix_NetOfSales, CumulativePurchases-CumulativeSales,
Matrix_PositiveOnly, IF(Matrix_NetOfSales<0,0,Matrix_NetOfSales),
Matrix_AmountsStillHeldFromEachPurchase, Matrix_PositiveOnly-IF(DatesRanked=1,0,INDEX(Matrix_PositiveOnly,XMATCH(DatesRanked-1,DatesRanked,0),SEQUENCE(,RowCount))),
Matrix_EliminateByDate, Matrix_AmountsStillHeldFromEachPurchase*(Dates<=TRANSPOSE(Dates)),
TRANSPOSE(MMULT(TRANSPOSE(E2:E5),Matrix_EliminateByDate))
)
Here, I'm using the LET function to break down the above into manageable parts. Here is what each of the above does:
Variable
How it works
Dates
Input date range from the spreadsheet
DatesRanked
In case your data isn't sorted, it ranks the dates
CumulativePurchases
This is a dynamic range that adds up all purchases that occurred before this purchase
CumulativeSales
Same thing, but for sales
RowCount
As the name suggests, the number of rows
Matrix_NetOfSales
This subtracts the sales from the purchases, as a matrix. This is important, because different dates draw upon different transactions
Matrix_PositiveOnly
Since cumulative sales may result in an entire transaction being eliminated from the calculation, we exclude any transaction that has a negative value still applied
Matrix_AmountStillHeldFromEachPurchase
This 'undoes' the cumulative operation, leaving just the portion of each transaction that still applies
Matrix_EliminateByDate
This ensures that we only apply transactions that occur on or before the date of the current transaction
Result
Finally, we use a matrix product between the cost per share per transaction, with the matrix of units from each transaction, to get the total value spent
Phew… That was a lot of work. To get the average price per coin, simply divide the total amount spent by the total number of coins (i.e. the first equation in this answer), and it should be done!
In finance (in common law countries), this solution is similar to Clayton's Rule: Which is that the newest credit(debit) is offset against the oldest debit(credit) when calculating interest… not a coincidence.
I don't have enough reputation to comment, but I don't think it's quite clear what you're trying to accomplish... if each line item has a quantity and a cost, why would you want the sum of all previous quantities? The cost per item should only be related to those items that were transacted in this line item?
I think, based on your formula in Column I, you are attempting to do an AVERAGEIF function. This would look like this:
I2=AVERAGEIF(B:B,B2,E:E)
This would make every row where B = "Buy" match each other, and every row where B = "Sell" match each other, which I think I understood you don't want. If you're wanting to weight the results based on the quantity sold, you can do that with a SUMPRODUCT:
I2=SUMPRODUCT(--(B:B=B2),E:E,F:F)/F2
Lastly, if I misunderstood this altogether, it sounds like you'd like column G to be the cumulative sum of quantity owned to date where BUYs are added and SELLs are subtracted. You could do that like this:
G2=SUMPRODUCT(--($B$2:$B2="Buy"),$F$2:$F2)-SUMPRODUCT(--($B$2:$B2="Sell"),$F$2:$F2)

Calculate peak equity in autofiltered sheet

I have a sheet which calculates the Peak Equity (CS) as well as the Total Equity (CR); both of these eventually wind up being different at some point, as one is calculating from the peak, whilst the other is just the current total.
The difficulty always comes with anything like this when autofiltering, so I need some assistance
I have a formula (two actually) which works well on Total Equity (CR), even when the sheet is autofiltered.
Both =10000+SUBTOTAL(109,CR$18:CR18) and =AGGREGATE(9,7,CR$18:CR18)+10000 do the job perfectly. I have used the SUBTOTAL one in this sheet
To calculate the Peak Equity (CS), requires finding the maximum of either the previous Peak Equity (CS) or current Total Equity (CR). The first row (CS18) is not able to use the same formula as there is no previous data row, so in this cell (CS18), I used the starting bank in the calculation instead.
Assuming the first row of data is 18, the basic formula in column CS is =MAX(CR19,CS18). This formula works fine when the sheet is not filtered, but falls over when it is autofiltered, for obvious reasons. Is there a way to have column CS be dynamic, always showing the correct Peak Equity?
As an afterthought, could the starting bank be possibly part of the formula to help resolve the issue? I'm just not sure how to address this issue. It doesn't matter what that bank is, but let's just use 10000 as a starting point for now if that helps.
Some additional explanation is needed so hopefully I can make what clearer
The first 17 rows are taken up with performance statistics. After that:
Profit or Loss is column N,
Current Bank is column CR,
Bank Highest Position (Peak) is CS
CR is the current total of what is visible in N - =10000+SUBTOTAL(109,N$18:N18)
CS needs to always be the larger of CR of the current row and CS of the previous row, but how is that possible in the first visible row as there is no previous row to use?
As the first 17 rows are taken up with data showing strike rates etc, whatever row is in position 18 will basically need to fulfil this =N18+10000 with 10000 being the starting bank
A couple of provisos change things a little, though, as CS can never be below the starting bank figure, let's assume 10000, so if the first row of N was a loss, CS would still be 10000, if that makes sense. As profit grows, CS also grows, but it can never go backwards, as it is always the peak. CR is simply the current $ amount in the bank. CS is the high point and will always be greater or equal to CR..
So I'll try it in English. CS would be something like this
IF current row is the first row, then the higher of N + 10000, or 10000. IF not the first row, then the higher of 10000, CR of current row or CS of row above.
I hope this helps a little bit, as I am not sure how to express this in a formula which will work when filtered
Thanks so much in advance
Regarding the starting bank value, how about wrapping the peak equity function inside IFERROR, like so:
IFERROR( function , starting bank value or cell reference)

EXCEL - IF statement, with words

Good afternoon,
I am looking for an Excel/GOOGLE Sheet =SUM(IF()) statement formula that will help to know if I have made or lost money in any given month. To save time when inputting the information, I would like to have once cell in the TOTAL row calculate what is a positive and negative number depending on the PAYMENT TYPE used, and printout the remainder.
This is also maintain inventory for when new items are added to my life during this one month period, because I'm just weird like that.
(See Google Sheet Link for example) ie Expense Report
ie. My expenses are arranged by in a column PAYMENT TYPE: CC (for credit card, negative), CASH (negative), GC (for gift card, not added), or DEPOSIT (for income, positive).
The "added negative/positive" is how the balances should look: red for money spent (CC, CASH), gray for no expense (GC), green for money earned (DEPOSIT).
The =sum(if()) formula would then be able to easily calculate the end result, either in red (money lost) or green (money earned).
If there is another formula outside of =sum(IF()) that would do this job, I am very interested in seeing how it would be applied, so I can learn it.
Thank you for your responses, in advance.
-ECP03
Unfortunately, my current network blocks Google Docs so I can't view your example doc. From what I've gathered, you have a a couple information columns (expense, amount, etc) and then one column that includes the payment type. Here are 2 ways you could do this:
Assumption: you have NAME (Range A1:A5), EXPENSE (Range B1:B5), and PAYMENT_TYPE (Range C1:C5) as your 3 columns with 4 total transactions. Header is the first row (A1:C1). This assumes you will never have more than 1000 transactions to keep track of; just modify 1000 to whatever new max you require.
1) This solution gives you your sum. It does not tell you the positive and negative contributions of the positives and negatives. For that see Solution 2.
Set the cell that you want your net income to be to:
=SUMIF(C1:C1000,"DEPOSIT",B1:B1000)-SUMIF(C1:C1000,"CC",B1:B1000)-SUMIF(C1:C1000,"CASH",B1:B1000)
2) This is the solution that shows both positive and negative contributions.
Set aside 3 cells (say E1, E2, and E3). Set E1 to:
=SUMIF(C1:C1000,"CC",B1:B1000)+SUMIF(C1:C1000,"CASH",B1:B1000)
This is your 'negatives' cell. Set E2 to:
=SUMIF(C1:C1000,"DEPOSIT",B1:B1000)
Set E3 to:
=E2-E1
Then all you have to do is use conditional formatting (if you don't know how to do this just let me know or Google it) to set cell E3 to be green if the amount in it is > 0, red if it is < 0, and gray if it is = 0.
Thank you, Judu Le.
That formula does the trick.
I did use your first answer.
ie. =SUMIF(C1:C1000, "DEPOSIT", B1:B1000) - (SUMIF(C1:C1000, "CC", B1:B1000)+SUMIF(C1:C1000,"CASH",B1:B1000))
The end result did not add or subtract the GC balance, which is what I wanted.
This worked perfectly. Thank you for your timely feedback.
-ECP03

Complicated formula required to work out costs including multiple discounts

I'm looking to compute and show individual row totals and a Grand Total. I just need the formulae to put in the boxes so the calculation is automatic but the problem is the calculations are a little complicated...
I'm using data validation to select the day type. This is what I think I need:
Assign a price to the day type (either Standard day = £23 or Extended day = £26).
Apply a volume discount where appropriate. If Jack is attending all week (5 days) and the day type is the same for all (all Standard or all Extended), the total cost is £100 (or £120)
Else the total number of days needs to be added up for Jack. (Number of days for each ‘day type’) and priced up.
For his siblings after the first, as above but apply an additional discount of 15%.
The grand total then needs to show at the bottom.
Well, it is not the best of data layouts but this may serve, in L6 and copied down to L13:
=IF(OR(A6="Brother",A6="Sister"),0.85* IF(COUNTIF(B6:F6,"Standard day")=5,100,IF(COUNTIF(B6:F6,"Extended day")=5,120,COUNTIF(B6:F6,"Standard day")*23+COUNTIF(B6:F6,"Extended day")*26)), IF(COUNTIF(B6:F6,"Standard day")=5,100,IF(COUNTIF(B6:F6,"Extended day")=5,120,COUNTIF(B6:F6,"Standard day")*23+COUNTIF(B6:F6,"Extended day")*26)))
and =SUM(L1:L16) in D16.
It would be better practice not to hard code the daily rates/discount, but extracting these from C1:D2 would have increased the length of the formula further.
Note also the result is not £429.95 (you may have changed your example after doing your calculations).

Resources