Countif after filterlist Excel - excel

I would like to see a working example of how to get this formula properly working
=SUMPRODUCT(SUBTOTAL(3,OFFSET($P$7,ROW($P$8:$P$5500)-ROW($P$7),,1)),--($P$7:$P$5500="74"))
What im trying to achieve is count all the cells within a range that value is greater than
zero, but i need to get that working after i apply a filter. I have seen several examples and havent get it working, with the subtotal fx.
Thanks in advance, for any help!

Working example:
O P
4
5 6
6
7 Filter Data
8 1 74
9 0 74
10 1 74
11 0 74
12 1 74
13 0 74
Formula in P5:
=SUMPRODUCT(SUBTOTAL(103,OFFSET($P$7,ROW($P$8:$P$20)-ROW($P$7),,1)),--($P$8:$P$20=74))
Now you can filter column O and P5 counts only the visible 74.
With function 103 in SUBTOTAL, I really count only the visible cells. This means, also the manually hidden cells are not counted. With function 3 only the out filtered cells are not counted. If cells are manually hidden, they are counted, even if they are not visible.
And I have used the value 74 instead of the text "74". So in my example the column P contains numbers, not text.
How it works:
The formulas within SUMPRODUCT are in array (matrix) context. This means they are handled as if they are used in array formulas.
In array context {ROW($P$8:$P$20)-ROW($P$7)} gets ROW($P$8)-ROW($P$7) = 1, ROW($P$9)-ROW($P$7) = 2, ROW($P$10)-ROW($P$7) = 3 and so on.
OFFSET($P$7,1,,1) will get $P$7+1Row = $P$8, OFFSET($P$7,2,,1) will get $P$7+2Row = $P$9 and so on.
So {OFFSET($P$7,ROW($P$8:$P$20)-ROW($P$7),,1)} gets {$P$8,$P$9,$P$10,...}
Within SUBTOTAL(103, {$P$8,$P$9,$P$10,...}) it counts 1 if {$P$8,$P$9,$P$10,...} is visible and 0 if not.
So the SUMPRODUCT results in
SUMPRODUCT({1,0,1,0,1,0,0,...}, --($P$8:$P$20=74))
The {($P$8:$P$20=74)} results in {TRUE,TRUE,TRUE,FALSE,TRUE,...} depend of if $P$8:$P$20=74. The -- (*-1*-1) gets this in numeric context, so that the TRUE = 1 and FALSE = 0.
So the SUMPRODUCT finally results in
SUMPRODUCT({1,0,1,0,1,0,0,...}, {1,1,1,1,1,1,0,...})
Greetings
Axel

Related

Excel how to look for value in table and return value from another cell

I have an issue in excel where I cannot get it to return a specific value.
I have a table of data like this
Week N1 N2 N3
w0 6 15 24
w1 5 8 9
w2 3 8 17
w3 20 23 31
w4 13 21 23
w5 6 12 15
w6 2 5 20
w7 10 20 21
the numbers in N1 N2 and N3 can change and are random.
What I need to be able to do is to lookup any number in the table and return the value in the weeks column.
so for example if I was looking for the number 20 it would return w6.
Ive tried various vlookups, Hlookups, Index and Match variations but just dont seem to be able to get this fairly simple thing to work.
Can anybody help me please, before I explode.
Try this:
= INDEX($A$2:$A$9,MATCH(1,MMULT(($B$2:$D$9=20)+0,{1;1;1}),0))
EDIT A slightly better formula:
= INDEX($A$2:$A$9,MATCH(TRUE,MMULT(($B$2:$D$9=20)+0,{1;1;1})>0,0))
It returns the first Week where a match is found in the table.
Obviously just replace 20 above with whatever value you want to look up.
See example below.
EDIT
More generally, instead of hardcoding {1;1;1} into the formula, you can make this dynamic, e.g.
= INDEX($A$2:$A$9,MATCH(1,MMULT(($B$2:$D$9=20)+0,TRANSPOSE((COLUMN($B$1:$D$1)>0)+0)),0))
Also, if you want to search the table from left to right instead of top to bottom, do this:
= INDEX($A$2:$A$9,MATCH(1,MMULT(TRANSPOSE((ROW($A$2:$A$9)>0)+0),($B$2:$D$9=20)+0),0))
Note, both of these are now array formulas (must be entered with Ctrl+Shift+Enter instead of just Enter.
Another method,
=index(A:A, iferror(match(G5, B:B, 0), iferror(match(G5, C:C, 0), match(G5, D:D, 0))))

Concatenate values in columns/rows and getting the value of the result

I have an excel worksheet with something like below. The desired output are as shown in column G and the last row, which concatenates all the values in columns/rows and gives the value of the resultant expression.
It's actually some kind of a puzzle where the aim is to replace some numbers with operators such that the values in G matches with a specified value. I am replicating the same in excel from a paper version.
A B C D E F G
3 3 33
4 1 + 2 43
4 0 + 5 6 4 604
7 3 2 / 1 2 61
3 7 2 7 3727
3 0 30
47 4033 304 0.4 2617 42
I have tried the following formula:
="="&A2&B2&C2&D2&E2&F2
However it gives the result in text format instead of 43, which I expected:
=41+2
Is there any way to give the final output as 43.
I developed (recorded and modified) a macro which simply copies the above result, paste it as values in Column H and then run 'text to columns' on the column H which gives me the desired output exactly as expected. However, I still can't figure out how to do the same with the row.
Is there any way to achieve the above with a formula only?
I want to avoid using macros as the undo functionality is lost but suggestions are welcome.
You could create a UDF that uses Application.Evaluate to evaluate the text string into a value. Then your formula would just need =Eval(A2&B2&C2&D2&E2&F2)
Function Eval(txt As String)
Eval = Application.Evaluate(txt)
End Function

Find all rows that contains 4 specific values?

I am using excel and I have a table of numbers with 6 columns from A to F and more than 1000 rows. For example, from my table,
4 17 37 38 47 53
8 43 54 55 56 60
4 18 21 25 38 57
15 25 37 38 58 59
4 16 19 20 27 43
18 32 47 50 54 56
i want to find if there is at least a row (it must be a row!) that contains the numbers 16 19 20 27. From this example, there is a match, but i don't know how to make a search or formula using four diferent numbers.
I feel like I need to use the match function but can't quite figure it out and I'm not sure about it. Does anyone know how to do this?
Thanks!
This should work:
=IF(AND(OR(A1=16,B1=16,C1=16,D1=16,E1=16,F1=16),OR(A1=19,B1=19,C1=19,D1=19,E1=19,F1=19),OR(A1=20,B1=20,C1=20,D1=20,E1=20,F1=20),OR(A1=27,B1=27,C1=27,D1=27,E1=27,F1=27)),"Yes","No")
Put it in a new column in the table. It will return a Yes if the row contains all 4 values, and a No otherwise. You can then filter the new column of Yes/No to search for a row with Yes
I put the four values you are seeking in I1:L1 and the array of data to be searched in A1:F#. Then in column G create a helper column that concatenates A:F into a delimited string. The formula in G1 is:
=":"&A1&":"&B1&":"&C1&":"&D1&":"&E1&":"&F1&":"
where I've used ":" for the delimiter (you can use any char that's not in your data).
The result in G1 is:
:4:17:37:38:47:53:
Now in H1 use this formula to search:
=NOT(ISERR(FIND(":"&$I$1&":",G1)*FIND(":"&$J$1&":",G1)*FIND(":"&$K$1&":",G1)*FIND(":"&$L$1&":",G1)))
Each FIND will return an INT if the value (with leading and trailing delimiters) is found and #VALUE! otherwise. So the product will be an INT if all values are found and #VALUE! otherwise. Wrapping the FINDs inside an ISERR makes the result prettier (TRUE/FALSE instead of #VALUE!), and inverting with NOT returns TRUE when all 4 values are found and FALSE otherwise.
Hope that helps.
Here's another way --- more elegant (no helper column). As before, I put the four values you are seeking in I1:L1 and the array of data to be searched in A1:F#. Then in column G use this ARRAY formula (CTRL-SHIFT-ENTER):
=NOT(OR(PRODUCT(A1:F1-$I$1)<>0,PRODUCT(A1:F1-$J$1)<>0,PRODUCT(A1:F1-$K$1)<>0,PRODUCT(A1:F1-$L$1)<>0))
Each PRODUCT term checks for the existence of one value and returns 0 when the value is found and a non-zero value otherwise. The results of each of the four PRODUCT terms is tested with <>0 which will return TRUE if a value is not found. Then OR with return TRUE if one or more values are not found and FALSE if all are found. That result is wrapped in a NOT so that the function result is TRUE when all four values are found.

Excel: Sum columns and rows if criteria is met

I have a sheet with product names in column I and then dates from there on. For each date there are numbers of how many pieces of a certain product have to be made. I'm trying to sum all those numbers based on a product type, i.e.:
I K L M ...
30.8. 31.8. 1.9. ...
MAD23 2 0 45 ...
MMR32 5 7 33 ...
MAD17 17 56 0 ...
MAD: 120 (2+0+45+17+56+0)
MMR: 45 (5+7+33)
What I'm doing now is sum the row first:
=SUM(K6:GN6)
MAD23 = 47
MMR32 = 45
MAD32 = 73
And then sum those numbers in column J based on part of the product name in column I:
=SUMIF(Sheet1!I6:I775;"MAD*";Sheet1!J6:J775)
MAD = 120
MMR = 45
Is it possible to do this with just one formula per criteria?
Just trying it on those three rows, I get
=SUM($K$6:$M$8*(LEFT($I$6:$I$8,LEN(I10)-1)=LEFT(I10,LEN(I10)-1)))
which is an array formula and must be entered with CtrlShiftEnter
That's assuming that I10 is going to contain some characters followed by a colon and you want to match those with the first characters of I6:I8.
=SUM(IF(MID(Sheet1!I6:I775,1,3)="MAD",Sheet1!k6:gn775,""))
With ctrl +shift+enter

Find what range a number belongs to

Ive written a function to calculate what MARK a student gets, based on a scoring table.
Why does my function work only for A mark?
This what the excel sheet looks like
COLUMN: A B C
Student SCORE MARK
1 adsf 90 A
2 asgfd 89 FALSE
3 A 90 100
4 B 81 89
5 C 71 80
6 D 61 70
7 E 56 60
8 Fx 0 55
This is the function:
{=IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))}
I'm using {} brackets for array functions. (CTRL SHIFT ENTER)
Thank you
You're on the right track but your formula is returning an array not a single value. Wrapping the result in LOOKUP should give the desired result:
=LOOKUP("Z",IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))
This returns the last matching grade since "Z" is larger than any other text value in the range.
A simpler method is:
=LOOKUP(-B1,-C$3:C$8,A$3:A$8)
The negative signs are needed so that the lookup values are in ascending order.

Resources