Excel: Formula containing a range inside of an array formula - excel

We've got data in Excel that looks like this:
| A | B | C |
—————————————————————————————————————————
1 | Amount | % Complete 1 | % Complete 2 |
2 | $ 1,000 | 25% | 50% |
3 | $ 600 | 50% | 100% |
4 | $ 2,500 | 75% | 100% |
Each line item is the cost of a task we've agreed to pay and each "% Complete" column is the percentage complete as of a specific date. We sum up the amounts owed as of that date to pay them based on the percentages, meaning that for the first "% Complete" column we can calculate the amount owed by using the array formula {=SUM(A2:A4*B2:B4)}.
However, subsequent columns need to pay only the difference between what's currently payable and what was already paid before.
To complicate things further:
The data will be blank if there was no change. For example, if something's 25% done as of the first check and still 25% done as of the second check, the corresponding cell in the second check's column will be blank.
The percentages can go down, leading to a negative amount to be paid. For example, if something's 50% done at the first check but progress goes backwards, the second check might have that at 25%, which means money is due back to us.
So for "% Complete" columns after the first, I need the last non-blank cell in the same row in a "% Complete" column prior to the current column. Using this explanation, I was able to create a formula that does that:
=$A2*(C2-LOOKUP(2,1/($B2:B2<>""),$B2:B2))
This will calculate how much is payable for a particular cell, so in the example above, it will produce $250: $1,000 * (50% - 25%). It will keep working as you continue along and will handle finding the last non-blank column.
I'd like to use the above formula in an array formula, but can't figure out how to do so.
So that gets us to the question: when a formula already has a range in it (i.e., the $B2:B2 in the formula above), is it possible to use that in an array formula and, if so, how? In a normal formula, you could covert a cell reference (e.g., A1) into a range (e.g., A:A), but is there some kind of syntax to use a range within a range?
Also happy to consider completely different ways to solve this problem, but due to how this spreadsheet is used, we unfortunately cannot use VBA.

To answer the last part of your post, I assume you will be updating and calculating the progress and payments periodwise. In which case, all you need to do is compare the current period with the previous. If such is the case, using the IF() function in a form something like this should serve the purpose.
=IF(Compl2>Compl1,Compl2*Rate,(Compl2*Rate-Compl1*Rate))

Related

Is there a way I can count a specific string (Product) in a column times by the neighboring cell (Quantity) so show how much of a product I have sold [duplicate]

I'm wondering if there is an easy way to do what I'm looking for. Basically, I have a balance sheet in Excel 2011 with a bunch of data. One specific piece of information I always want visible is the amount that hasn't been reimbursed. In other words, I have a column for the amount paid and another for whether or not it has been reimbursed (Yes/No). I want to sum all of the amounts paid where the reimbursed field is equal to 'No'.
I recognize I can sum the entire column and filter out those that have been reimbursed, but I'd like it to display the full amount regardless of what filter is on (or if no filter is on).
I wasn't able to find good keywords to describe this to Google, so I'm asking here. I would like to accomplish this in Excel, not in an external program or script.
If column A contains the amounts to be reimbursed, and column B contains the "yes/no" indicating whether the reimbursement has been made, then either of the following will work, though the first option is recommended:
=SUMIF(B:B,"No",A:A)
or
=SUMIFS(A:A,B:B,"No")
Here is an example that will display the amounts paid and outstanding for a small set of sample data.
A B C D
Amount Reimbursed? Total Paid: =SUMIF(B:B,"Yes",A:A)
$100 Yes Total Outstanding: =SUMIF(B:B,"No",A:A)
$200 No
$300 No
$400 Yes
$500 No
You could do this using SUMIF. This allows you to SUM a value in a cell IF a value in another cell meets the specified criteria. Here's an example:
- A B
1 100 YES
2 100 YES
3 100 NO
Using the formula: =SUMIF(B1:B3, "YES", A1:A3), you will get the result of 200.
Here's a screenshot of a working example I just did in Excel:
You should be able to use the IF function for that. the syntax is =IF(condition, value_if_true, value_if_false). To add an extra column with only the non-reimbursed amounts, you would use something like:
=IF(B1="No", A1, 0)
and sum that. There's probably a way to include it in a single cell below the column as well, but off the top of my head I can't think of anything simple.

How to sum up certain cells in a row based on that adjacent cells

I have the following table:
ID 268 287 396
Simulation | Leaving Date | Benefit on Leaving (if any) | Leaving Date | Benefit on Leaving (if any) | Leaving Date | Benefit on Leaving (if any)
1 2040 $50 2040 $100 2035
I want to sum up the benefits on leaving for each ID for any given year. For example, if I would like to sum up the benefits on leaving for 2035, it would be 0. However, if I were to sum up the benefits on leaving for 2040, it should give $50 + $100 = $150.
How can I do this in Excel? I know how to use INDEX & MATCH to find a particular leaving date and take the benefit on leaving, which is simply the next cell. However, in some cases, there will not be just one person leaving in that given year (the INDEX & MATCH method I know of can only search and return unique values). Moreover, for certain IDs, when they leave, they do not receive any benefit, so that corresponding cell is blank, as seen for ID 396.
I would not like to "brute force" this, as what I have shown is only a short example, but in actual fact, the row for each simulation is about 100 columns long (I have about 50 IDs) and I need to do this for 1000 simulations.
In summary,
The "Benefit on Leaving (if any)" column always follows a "Leaving Date" column.
Each "Leaving Date" column is like my criterion - within each row, I need to find all the "leaving dates" that I am looking for and sum the corresponding benefits on leaving. If there is no benefit on leaving for that leaving date, then I take that specific value to be 0.
Any intuitive suggestions will be greatly appreciated :) and I apologise if a similar question has been asked before! I could not find any satisfactory solutions after much searching.
Option 1: Use SUMIFS with offset ranges (though does assume that no Benefit will be equal to 2040).
=SUMIFS(B2:F2,A2:E2,2040)
Option 2: Use SUMPRODUCT with offset ranges.
=SUMPRODUCT(B2:F2*(A1:E1="Leaving Date")*(A2:E2=2040))

Use SUMIF with transformed text to number

So I have a monthly budget in Excel that I'm using to keep track of making sure all of my recurring bills get paid on time.
Let's assume I have a table formatted like this:
Bill | Due Date | Amount Projected | Actual Amount | Diff
Mortgage | 1st | $1,500 | $1,510 | -$10
Water Bill | 13th | $30 | $25.80 | $4.20
I get paid on the 1st and the 15th, and I'm trying to get two rows that give a sum of all of the bills that are due within the first paycheck, and a sum of those that are due after.
So I'm trying to use the SUMIF function, however because the DUE DATE column is text and not date so that I get the 1st, 2nd, etc, I'm not sure how to run a comparison on this.
So I have the formula to get rid of the th, nd, etc as:
=LEFT(B2, LEN(B2)-2)
If it didn't have the th, or nd, the SUMIF function would look like this:
=SUMIF(C2:C3, "> 15", B2:B3)
But I just can't figure out how to combine the two formula. Is there any special character that runs the transform on the cell where I can pass that into the formula, without having an intermediate cell somewhere to just hold the 1, or 13 for the date due?
I know there are other ways to do this like just sorting the columns by due date and then only selecting that range, but I'd like to not have to manually change a bunch of other "reporting" columns every time I add or remove a bill.
Thanks for any help in advance.
=SUMPRODUCT((left(B2:B3,len(B2:B3)-2)<15)*C2:C3)
SUMPRODUCT performs array like operations. As such avoid using full column reference such as B:B.

Excel Rolling Mean of 3 Similar Consecutive Observations

I'm trying to find the rolling mean of time series while ignoring values that do not follow the trend.
x
869
1570
946
0
1136
So, what I would want the result to look like is...
x | y
869 | 0
1570 | 0
946 | 1128.33
3 | 0
1136 | 1217.33 ([1136+1570+946]/3)
900 | 2982 ([946+1136+900]/3)
860 | 2896
The tough part here is if the row I'm on is a trending value I want to take the 3 previous trending values and find them mean of them, but if it's a non-trending value I want it to just zero out. Sometimes I might have to skip 2 or 3 previous lines to get 3 trending values to take the average as well.
So far I've been using array, RC formulas in a VBA macro form, but I'm not sure I could use RC here or if it has to be something else completely. Any help would be greatly appreciated.
I believe I can help you with your problem. First three notes:
1) It appears to me that you are trying to do DCA on smoothed production profiles, ignoring months without a complete record or no data. I'm making this assumption since you mentioned this was time series data but didn't give a sample rate. 2) I've added some extra 'data' for the sake of demo-ing. 3) In your example you shared, the last two values in your 'Y' column it looks like you may have summed but have forgotten to divide.
The solution I came up with has three parts: 1) create a metric to identify 'outliers'; 2) flag 'outliers'; 3) smooth non-flagged data. Let's establish some worksheet infrastructure and say that your production values are in column B and the associated time is in column A as follows:
Part 1) In column 'C', estimate a rough data value based on a trend approximated from two points on either side of your current time step. Subtract the actual value from this approximation. The result will always be positive and quite large for a timestep with little or no production.
=(INTERCEPT(B1:B6,A1:A6)+(A4*SLOPE(B1:B6,A1:A6)))-B4
Part 2) In column 'D', add a condition for when the value computed above is larger than the actual data point. Have it use '0' to identify a point that shouldn't be included in your average. Copy this down to the end of your data as well.
=IF(C4>B4,0,1)
Our sheet now looks like this:
3) Your three element average can now be computed. In the last cell of column 'E', enter the following array formula. You have to accept this formula by pressing ctrl + shift + enter. Once that is done fill the column from bottom to top:
=IFERROR(IF(D17=1,AVERAGE(INDEX(B12:B17,MATCH(2,1/(FIND(1,D12:D17)))),INDEX(B12:B16,MATCH(2,1/(FIND(1,D12:D16)))-COUNTIF(D17,"=0")),INDEX(B12:B15,MATCH(2,1/(FIND(1,D12:D15)))-COUNTIF(D16:D17,"=0"))),0),"")
This takes averages the most recent three values and allows for a skip of up to three time steps of outlier data per your problem statement. For an idea of how the completed sheet looks:
This was a fun challenge, I have some ideas for a more efficient formula but this should get the job done. Please let me know how this works for you!
Cheers
[EDIT]
An alternative approach which allows the user to specify the number of previous entries to include is detailed below. This is a more general (preferred alternative) and picks up in place of the previously described step 3.
3Alt) In cell G2 enter a number of previous values to average, for this example I am sticking with 3. In cell E4 enter the following array expression (ctrl+shift+enter) and drag to the end of column E:
=IFERROR(IF(D4=1,SUM(INDEX(D:D,LARGE(($D$4:D4=1)*ROW($D$4:D4),$G$2)):D4 * INDEX(B:B,LARGE(($D$4:D4=1)*ROW($D$4:D4),$G$2)):B4)/$G$2,0),"")
This uses the LARGE function to find the 'nth' largest value, where n is the number of preceding values from the current time-step to average. Then it builds a range that extends from the found cell to the current time step. Then it multiplies the flags (0's and 1's) by each month's production value, sums them and divides by n. In this way months flagged as bad are set to 0 and not included in the sum.
This is a much cleaner way to achieve the desired result and has the flexibility to average different periods of time. See example of the final value below.

how to calculate incremental total amount paid everytime an amount is entered in another column

The Total Amount is incrementing(single cell:H2) when value is entered in the same cell(G2)..e.g today if you enter in G2 the value of 30 the total amount in H2 is 30;when you enter tomorrow in G2(same cell) the value of 50, the total amount in H2 should be 80;and when you enter again 80 in the same cell(G2)the next day, the total amount should now be 160...hope you could shed a light on this...Thank you very much...
UPDATE:
I found this to be working, no VBA required. It should be quite simple actually. Start with your file like this:
| | G | H |
|---+-------------+-------------------|
| 1 | Amount paid | Total Amount Paid |
| 2 | 0 | 0 |
Now go to your settings (for 2010 File -> Options -> Formulas, for 2003 Tools -> Options -> Calculation), tick 'Enable iterative calculation' and set 'Maximum Iterations' to 1. Now in H2 enter your formula as =G2+H2. This is a circular reference (the simplest one there is, cell H2 refers to itself in the calculation) which won't work properly unless you set your calculation settings right. If you set your calculation in the same settings tab to manual then the total will only update when you press F9. If you set it to automatic it will automatically update when you make a change in cell G2.
Original answer
Assuming your data starts in A1 this formula would sum up all numbers in column A
=SUM(A:A)
If you won't have other stuff in this column (and don't mind the obvious overkill) this will work. If you need to be a little more specific and update a range that dynamically grows/shrinks we need to be a little bit more clever and use INDIRECT or OFFSET as follows
=SUM(INDIRECT("A2:A"&COUNTA(A:A)))
=SUM(OFFSET(A2,0,0,COUNTA(A:A)-1,1))
If you don't know these functions look into them in the Help, they can be very useful.
Another thing to clean things up would be to define a named range with the above e.g. OFFSET formula piece and use that in your formula(s). This makes it easier to repeatedly use the specified range and improves the readability of your formulas. I would define PaidRange as follows
=OFFSET(A2,0,0,COUNTA(A:A)-1,1)
and then your formula would read
=SUM(PaidRange)

Resources