Count Excel cells in a row until the sum is reached? - excel

I have two rows and want to count the number of cells in the row-2, offset by one column, I need to sum up to reach but not exceed the number in row-1
A B C D E F G
20 39
2 3 15 12 8 10
x y
So "x" should be 3 (2+3+15 < 20)
and "y" should be 4 (3+15+12+8 < 39)
I tried all sorts of formulas, but none worked, this one is supposed to work but doesnt:
=MATCH(A1,INDEX(SUBTOTAL(9,OFFSET(A2,,,,COLUMN(A2:G2))),0))
edit
The actual Excel had slightly different numbers
F D E F G H I J K L M N O P Q R
3404 1409 312971 290486 255425 233206 209780 852766 791217 762958 707437 705119 blank 23141
1135 470 104324 96829 85142 77735 69927 284255 263739 254319 235812 235040 blank 34212
Top row is 44 and the bottom one is 46
The formula I use is :
=MATCH(F44,INDEX(SUBTOTAL(9,OFFSET(F46,,,,COLUMN($F$46:$R$46))),0))
** Edit 2 **
Also - how can I exclude blank cells in this?

Related

Excel Swap Column of number

I am creating an excel file to swap excel columns which contains the number corresponding to the ASCII character such as low letter, upper letter, number, special characters.
Here is the original table and the corresponding letter to the number
A B C D E F G H
1 2 3 4 5 6 7 8
I want to swap each of the cell to the end. Meaning I need to swap 1 to 8. 2 to 7. 3 to 6.
A B C D E F G H
8 7 6 5 4 3 2 1
I would want to use the excel function to do this. Is there a way to achieve this? I have 156 columns.
what about this method.
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
If your data is always ordered then sorting would work.
But let's assume your data is not always alphabetically or numerically sortable, you can use a formula to reverse an unsorted list:
-
A
B
C
D
E
F
G
H
1
A
B
C
D
E
F
G
H
2
1
2
3
4
5
6
7
8
3
8
7
6
5
4
3
2
1
Rows 1 and 2 are your original data. Row 3 is the reversing formula.
Add the formula below into cell A3
=INDEX($A$2:$G$2, COLUMNS(A2:$G$2))
Note (important) that the first Range of the INDEX is absolute $A$2:$G$2, but the only the last value of the columns range is absolute A2:$G$2 (no dollars)
Either drag cell A3 across to H3 or copy cell A3 and paste over B3:H3
This has an advantage over plain sorting in that it can reverse unsorted lists for you.

How to find if a number in a row matches a number in a column, and then automatically offset the number in the column to another value

How to find if a number in a row matches a number in a column, and then automatically offset the number in the column to another value. For example:
Row 0 1 2 3 4 5
Answer x x x x x x
Column
0 100
1 340
2 500
3 266
4 455
5 800
So if "0" in the Row array matches "0" in the Column array, then show 340 and so on. I can to this with nested IF statements but is there an easier way if you have 100s of columns. Thanks

Count using a category and Median using a category

I have two problems here.
The data is as follows:
Col X Col Y
A 10
A 12
A
A 32
B 11
B 31
B 9
C 8
C 7
C 3
D 1
D 3
D
D 9
I need to do the following:
Count the entries in Column Y using the Categories in Column X, for ex. A repeats 4 times in Column X but has 3 total corresponding numbers in column Y, i need the 3 count of the numbers in Column Y.
Calculate the median of those numbers using the category (excluding blanks whenever there are, not to be assumed as 0 by the code), for ex. Median for A is 12, Median for D will be 3.
Please help.
So 1 is:
=COUNTIFS(X:X,"A",Y:Y,"<>")
2 is:
=MEDIAN(IF(X:X="A",IF(NOT(ISBLANK(Y:Y)),Y:Y)))
Hold down ctrl + shift when you're using 2 as it's an array formula

Identify Rows with Same Values in 2 Different Columns

I have a data set of roughly 405,000 rows and 23 columns. I need the records where the value in column "D" is the same as the value in column "H" for that row.
So for
A B C D E F G H
13 8 21 ok 3 S - of
51 7 22 no 3 A k no
24 3 23 by 3 S * we
24 4 24 we 3 S ! ok
24 9 25 by 3 S # we
75 2 26 ok 3 S 9 ok
etc...
I'd get back the 2nd row, the 6th row, etc...
A B C D E F G H
51 7 22 no 3 A k no
75 2 26 ok 3 S 9 ok
Based on other posts like: Formula to find matching row value based on cells in multiple columns I tried using a Pivot Table, but it complains I can't put either of my two columns in the "Columns" area because there is too much data. With both columns in the "Rows" area, I get a relationship of D to H, but I can't then find a way to filter on only those where D = H.
I've also looked into countifs(), vlookup, and index / match functions, but I can't figure this out. Help please.
I would do a simple "IF()" formula in a new column.
For your example add a new column I and use the following formula in the first data row (I2):
=IF(D2=H2,"Yes","No")
Fill down to the end of the data.
Then using Excel filters or countif you can check the number of "Yes" vs "No" in your data.

excel formula depending on dynamic values in different columns

I am trying to create an excel formula using SUM and SUMIF but cannot find how to.
I have a first column(A) which is the total time of a piece of work and then for each row the time spent in that task during each day(columns B, C, ...).
For each day(columns B, C, ...), the formula would return the sum of only those values in column A that(for that specific column), relate to task that have been completed that day: the sum of all cells within a row is equals or more than the time the task was allocated.
Example for one 12-hours task:
A B C D E
12 4 6 2 0
Using the formula:
A B C D E
12 4 6 2 0
0 0 0 12 0
where 12 is displayed in column D because 4 + 6 + 2 = 12(Column A)
Second example(3 tasks):
A B C D E
10 9 0 1 0
21 8 8 5 0
5 0 0 3 2
Using the formula:
A B C D E
10 9 0 1 0
21 8 8 5 0
5 0 0 3 2
0 0 0 31 5
Where:
31(Day D) = 10(Task 1 is finished that day) + 21(Task 2 is finished that day too)
5(Day E) = Task 3 is finished that day
Tried this formula (for Day B):
SUMIF(B1:B3,">=A1:A3",A1:A3)
(Sum those values in column A if the cells in that row p to column B(in this case just B) are >= than those iterated).
Then for column C, it would be,
SUMIF(C1:C3 + B1:B3,">=A1:A3",A1:A3)
The above examples did not work(first returns zero, second is an invalid formula),
Any ideas?
Thank you.
Formula below given by user ServerS works fine:
Col B:
=IF(SUM(B2)=A2,A2,0)+IF(SUM(B3)=A3,A3,0)+IF(SUM(B4)=A4,A4,0)+IF(SUM(B5)=A5,A5,0)
Col C:
=IF(SUM(B2:C2)=A2,A2,0)+IF(SUM(B3:C3)=A3,A3,0)+IF(SUM(B4:C4)=A4,A4,0)+IF(SUM(B5:C5)=A5,A5,0)
Col D
=IF(SUM(B2:D2)=A2,A2,0)+IF(SUM(B3:D3)=A3,A3,0)+IF(SUM(B4:D4)=A4,A4,0)+IF(SUM(B5:D5)=A5,A5,0)
However there are two inconvenients:
if new rows are added it needs to be adapted and include another IF(). Would be better to have a generic SUM if IF's
Trying to propagate the formula to adjacent cells is not possible as it would change part of the formula like "=A2,A2,0" to "=A3,A3,0" which needs to keep the same.
Any other ideas that improve this, if possible, are appreciated.
You can avoid using IF with a sumproduct. This method allows use to insert any row you want. Make sure range are correct (eg A2:A5 with 5 the last row used). I would go for this :
in column B :
=SOMMEPROD(($A$2:$A$5)*($A$2:$A$5=(B2:B5)))
in column C :
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5)))-B6
in column D
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5+D2:D5)))-C6-B6
in column E
=SUMPRODUCT(($A$2:$A$5)*($A$2:$A$5=(B2:B5+C2:C5+D2:D5+E2:E5)))-D6-C6-B6

Resources