In Excel, is there an efficient way to sum overlapping Named Rangess? - excel

In Microsoft Excel, I have a named (2D) range. For simplicity, let's assume it looks like this:
1
2
3
4
5
5
4
3
2
1
This represent a time series growth curve, where N number of these could kick off in any point in time. I'm looking for an efficient way to calculate what the cumulative sum of these at any point in time would be, given that N start at that point in time.
So for example, if one starts at time 0, and one at time 3, and two at time 7:
0
1
2
3
4
5
6
7
8
9
1
0
0
1
0
0
0
2
0
0
Then the cumulative total would be:
0
1
2
3
4
5
6
7
8
9
1
2
3
4
5
5
4
3
2
1
1
2
3
4
5
5
4
2
4
6
---
---
---
---
---
---
---
---
---
---
1
2
3
5
7
8
8
10
11
11
I'd like to write a formula that gets to that total without having to use those extra rows to sum over, but can't figure out how.

Use SUMPRODUCT and INDEX:
=SUMPRODUCT(INDEX($M$1:$V$1,(COLUMN()-COLUMN($A$1:A1)+1)),$A$2:A2)
The ranges are dynamic and increase as it is pulled over.
with versions that are not Office 365 we need to trick INDEX into accepting an array:
=SUMPRODUCT(INDEX($M$1:$V$1,N(IF({1},(COLUMN()-COLUMN($A$1:A1)+1)))),$A$2:A2)
This would then be confirmed with Ctrl-Shift-Enter to make it an array formula.

Related

Excel - Shift starting column right by x

In excel I have a dataset. This represents how much stock of 2 products is sold in the first, second, third, etc... month of the product being on the shelves (starts in A1):
Month 1 2 3 4 5 6 7 8 9 10 11 12
Product 1 3 5 2 1 6 1 2 4 7 2 1 5
Product 2 2 1 5 6 2 8 2 1 2 3 4 9
However, the first product sales do not always occur in month 1. They occur in month X. Is there a way (not VBA or copy and paste) of shifting the entries right by 'x' so they align with the month.
Example for data above
Product 1 starts in month 2
Product 2 starts in month 5
Month 1 2 3 4 5 6 7 8 9 10 11 12
Product 1 0 3 5 2 1 6 1 2 4 7 2 1 5
Product 2 0 0 0 0 2 1 5 6 2 8 2 1 2 3 4 9
*0 not required (great if possible), but more for illustration
Thanks
I have created a simple example that does the same job. The shown formula is copied over the shown cells in the row of new data. (The number '2' in the formula refers to the column number of the starting data cell which is column B, hence 2.)

Pandas DataFrame: how do we keep columns based on the index name?

I seem to run into some python or enumerate bugs that I am not quite sure how to fix it (See here for more details).
Long story short, I desire to see multiple data sets that has a column name of 0,4,6,8,10,12,14.
0 4 6 8 10 12
1 2 5 4 2 1
5 3 0 1 5 10
....
But my current data looks like the following
0 4 2 6 8 10 12
1 2 5 4 2 1
5 3 0 1 5 10
....
Therefore, I would like to add a code that keeps columns based on the index number (including only 0,4,6,8,10,12).
Is there a pandas function that can help with this?

In excel, how to use an array formula to sum a range to offsets of itself, generating a new "sum" range?

I'd like to use an array formula to sum a range to multiple offsets of itself: for example, given the following range: {3,4,5,6,7} (say in cells A1:A5), I'd like to get the range added to itself, say 4 times, but each addition is offset by one column. So the answer would be a range equal to {3, 3+4, 3+4+5, 3+4+5+6, 3+4+5+6+7, 4+5+6+7, 5+6+7, 6+7, 7}
Here is an example, offset by rows:
3
4 3
5 4 3
6 5 4 3
7 6 5 4 3
0 7 6 5 4
0 0 7 6 5
0 0 0 7 6
0 0 0 0 7
=
3
7
12
18
25
22
18
13
7
Put the following in your first desired cell:
=IF(ROW(1:1)< COUNT($1:$1)*2,SUM(INDEX($1:$1,IF(ROW(1:1)<COUNT($1:$1),1,ROW(1:1)-COUNT($1:$1)+1)):INDEX($1:$1,MIN(ROW(1:1),COUNT($1:$1)))),"")
Then copy down. As numbers are added or subtracted from the first row the answer will change to match. Just copy down sufficient rows to cover twice the greatest number of values in row 1.

find number appears more

1 2 2
4 5 4
3 3 3
0 1 0
1 2 2
4 4 3
4 5 4
4 5 4
3 4 4
3 4 4
4 4 4
3 4 3
I have above three columns in excel,how to find the number that appears more times, for example, first row is 2 (because it has two 2 and one 1)
Assuming your layout is such that the first column is A, second column is B, etc., then you could put the following in cell D1:
=IF(ISNUMBER(MODE(A1:C1)),MODE(A1:C1),0)
This also outputs 0 in case there is a tie. You can replace the 0 with whatever excel expression you want if you don't want ties to result in a 0.

how find unique value from Different column

A B ANSWER
1 1 1
3 3 3
1 2 1
2 4 2
4 4 4
5 5 5
6 6 6
i have used this function to get above answer "=IF(ISERROR(MATCH(A2:A8,$B$1:$B$8,0)),"",A2)"
but I need answer like this i have given below (suppose if you take value in A column "1"
Which is repeated only once in column B)
A B ANR
1 1 1
3 3 3
1 2 0
2 4 2
4 4 4
5 5 5
6 6 6
I've just wrapped your formula in a condition that returns 0 where the count of the A value from start to the current row is more than one:
=IF(COUNTIF(A$1:A2,A2)>1,0,IF(ISERROR(MATCH(A2:A8,$B$1:$B$8,0)),"",A2))
.
An alternative formula that gives the same results as above for the sample data provided but may (or may not) suit the additional requirements mentioned in a comment:
=IF(COUNTIF(A$2:A$10,A2)<=COUNTIF(B$2:B$10,A2),A2,IF(COUNTIF(A$2:A2,A2)>COUNTIF(B$2:B$10,A2),0,IF(COUNTIF(A$2:A$10,A2)>COUNTIF(B$2:B2,A2),A2,0)))

Resources