In the above image, I want to check on which row the input 1,2,3 & 4 are matching. So in this example I want result 3 as it has "1 1 0 0" and the box on the top also has "1 1 0 0".
I tried following array formula but it's not working.
=IF((C10:C25=C3)(D10:D25=C4)(E10:E25=C5)*(F10:F25=C6),G10:G25,"")
It would be great if this can be done without using any intermediate result columns.
Assuming your first list is in B2:B5 and the bigger grid in D2:G17, with the result column in H2:H17, use this array formula:
=INDEX(H2:H17,MATCH(B2&B3&B4&B5,D2:D17&E2:E17&F2:F17&G2:G17,0))
Related
I have a sparse dataset in excel, e.g.:
1 0 2 4 5 8
2 3 0 0 0 6
Zeros represent missing values.
I want to sum the first 3 nonmissing values in each row using Excel.
Thanks
For a normally entered formula, try:
=SUMPRODUCT(N(OFFSET(A1,0,AGGREGATE(15,6,1/1/(A1:K1<>0)*COLUMN(A1:K1),{1,2,3})-1)))
For a sum against EACH row, you can do as below:
Array formula - use:
Ctrl+Shift+Enter
=SUM(INDEX($A1:$F1, 1, 1):INDEX($A1:$F1, 1, SMALL(IF($A1:$F1, COLUMN($A1:$F1) - COLUMN($A1) + 1), 3)))
Image shows second row selected, but formula I typed shows first row.
I don't have Excel at home to test it, but you can try entering this formula with Ctrl+Shift+Enter:
=SUM(OFFSET(A1:F1,0,0,1,SMALL(IF(A1:F1,COLUMN(A1:F1)),3)))
The SMALL(IF(A1:F1>"",COLUMN(A1:F1)),3) part should return the index of the third non-zero cell.
If you have the latest version of Excel 2016 and you know for sure that each cell will only contain one digit, you can leverage the CONCAT Function:
=SUM(--MID(SUBSTITUTE(CONCAT(A1:F1),0,""),{1,2,3},1))
I have the following Excel spreadsheet:
A B C
1 50 20 =IFERROR(A1/B1,"") = 2.5
2 60 0 =IFERROR(A2/B2,"") = ""
3 80 0 =IFERROR(A3/B3,"") = ""
4 10 50 =IFERROR(A4/B4,"") = 0.2
5
6 COUNT: 2
7
In Cell C6 I want to count the number of items in the list which are not " " according to Column C.
I tried to do this with the following formula:
=COUNTIF(C1:C4;"<>""")
However, this formula gives me back the value 4 instead of 2.
Therefore, I guess the issue is related to the IFERROR functions which I use in Column C.
Do you have any idea how I have to change the COUNTIF formula to only count the cells without " "?
I know - in this specific case - I could solve the issue by using the COUNTIF formula over Column B. However, I would prepfer a solution that goes over Column C.
Instead of COUNTIF use SUMPRODUCT as
=SUMPRODUCT((C1:C4<>"")*1)
This can be tricky. I usually count the blanks using COUNTBLANK and take that away from the total count
`=COUNTA(D1:D4)-COUNTBLANK(D1:D4)`
Also because in this case your output is the result of a division you could use =COUNTIF(D1:D4,">-1") to count everything with a value zero or above.
Please see https://www.ablebits.com/office-addins-blog/2014/07/02/excel-countif-examples/#countif-blank
In your example, the formula could be
=COUNTIF(C1:C4;"")
I need to compare two sets of two columns and find the count of number of IDs that match a certain criteria.
A B C D E
ID: ListNum: RefNum: List2Num: Ref2Num:
1 10 5 12 6
2 3 7 10 2
3 12 8 1 5
4 2 15 13 4
5 4 11 2 8
6 6 9 1 3
Let's say that the cell containing ID = "1" is A2 and it goes down to A7
I have to count the number of IDs that have a ListNum that is higher than the RefNum AND also have a List2Num that is higher than Ref2Num. Both criteria must be satisfied in order to count the ID.
I used the following formula: =COUNT(IF(B2:B7 > C2:C7) & (D2:D7 > E2:E7))
I get a value, but it's not the right count (it's taking the total for both conditions rather than only counting it once). The final answer should be 1. Any help would be appreciated, thank you!
One reason why yours didn't work: In your formula you use & to mean AND, but & actually concatenate strings.
Option 1: Array Formula
IF and AND don't work on arrays so a normal formula containing them won't work. So use an array formula instead:
You need to enter this as an array formula (you need to press control-shift-enter instead of enter when you put the formula in):
=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))
When it is in the cell it will display in braces to show it is an array formula. Like so:
{=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))}
In this formula the X>Y will return 1 or 0 for true or false. So multiplication is the same as AND and addition is the same as OR. Then (B2:B7 > C2:C7)*(D2:D7 > E2:E7) means B2:B7 > C2:C7 AND D2:D7 > E2:E7 and it returns an array of 1 and 0 which are then summed up to get the count.
Option 2: SUMPRODUCT
There is a normal function whose sole purpose is to multiply arrays together and then add them up the same way as the array formula does: SUMPRODUCT
The problem with SUMPRODUCT is that the arrays must be numbers and not logical true and false values so any of these works:
=SUMPRODUCT(--(B2:B7 > C2:C7),--(D2:D7 > E2:E7))
=SUMPRODUCT((B2:B7 > C2:C7)*1,(D2:D7 > E2:E7)*1)
=SUMPRODUCT((B2:B7 > C2:C7)+0,(D2:D7 > E2:E7)+0)
And this does not:
=SUMPRODUCT((B2:B7 > C2:C7),(D2:D7 > E2:E7))
But SUMPRODUCT is a normal function so you don't need to enter it with control-shift-enter.
Try entering this formula into cell F1:
=IF(AND(B1 > C1, D1 > E1), 1, 0)
Then just take the sum of the F column for however many rows you really have, and you should be left with the answer (which is 1 for the sample data you gave above).
If you put a simple AND formula next to your table, you can autofill that all the way down. Next, you could count the number of True values in that column (see pic). You could combine into an IF statement as Tim suggests.
The two formulas would be
"=AND(B2>C2,D2>E2)"
"=COUNTIF(G2:G7,TRUE)"
Link to picture of possible solution
Image for reference
I'm trying to achieve the following:
if(cell A1 is found in list 1), for each row in which it's found and if(C4:C10 > B4:B10), then median(the subtraction between C and B values, for every row that has text1).
I've tried two 2 different formulas:
1 - {=MEDIAN(IF(AND((C4:C10>B4:B10);(B4:B10=A1));(C4:C10-B4:B10)))}
2 - {=MEDIAN((C4:C10>B4:B10)*(B4:B10=A1)*(C4:C10-B4:B10))}
For median it always returns 0 and for the average really small values that aren't accurate. I'm sure the median and the averages aren't correct.
What would the problem be?
Also, how would I use something like:
{=MEDIAN((C4:C10>B4:B10)*(B4:B10=A1)*(C4:C10-B4:B10))}
If one the columns had text in some rows? (which isn't the case for the former problem, but it has arisen before).
text1
list 1 list 2 list 3
text2 1 5
text4 2 4
text1 4 6
text4 1 6
text1 4 5
text4 2 4
text1 3 3
You can't use AND function in these type of formulas because AND returns a single result (TRUE or FALSE) not an array as required.
Your second formula is closer but by multiplying all the conditions you will get zeroes for every row where the conditions are not met, hence skewing the results.
You can use either one of these similar versions:
=MEDIAN(IF((C4:C10>B4:B10)*(A4:A10=A1);C4:C10-B4:B10))
=MEDIAN(IF(C4:C10>B4:B10;IF(A4:A10=A1;C4:C10-B4:B10)))
both need to be confirmed with CTRL+SHIFT+ENTER
To handle text in columns B or C (and to make the formula ignore those rows but work otherwise) you can add an extra IF function like this
=MEDIAN(IF(C4:C10>B4:B10;IF(A4:A10=A1;IF(ISNUMBER(C4:C10-B4:B10);C4:C10-B4:B10))))
All formulas will work equally well with AVERAGE function in place of MEDIAN
Another way to get the MEDIAN while ignoring text is to use AGGREGATE function like this:
=AGGREGATE(17;6;C4:C10-B4:B10/(C4:C10>B4:B10)/(A4:A10=A1);2)
That doesn't need "array entry" but will only work in Excel 2010 or later versions. There's no simple equivalent for AVERAGE
17 denotes QUARTILE function - second quartile is the equivalent of median
See attached screenshot demonstrating the last two formulas with your sample data....and some added text
Supposing that the values in column C that is list 3 are bigger than those in column B that is list 2, then you can use the following formula:
=MEDIAN(IF((A4:A10=A1)*(C4:C10>B4:B10);C4:C10-B4:B10))
this is an array formula, so press ctrl+shift+enter to calculate the formula.
tell me if it doesn't work.
I have this text in an Excel cell in column A: 2 / 12 and want to make this subtraction in another cell in column B: =12-2.
For example, values in column A are:
2 /12
3 / 10
0 / l8
0 / 0
and I want to do this subtraction in column B:
= 12-2
= 10-3
= 18-0
= 0-0
I want to appear only the results ex. 10, 7, 18, 0
How can I do this for multiple cells?
Please try:
=RIGHT(A1,FIND("/",A1))-LEFT(A1,2)
copied down to suit.
Excel has built in Text to columns feature that would probably be useful in this case.
Under data
click Text to columns
selected Delimited
Click Next
Under Delimiters in "Other" enter "/" (without parenthesis) click finish.
That should give you 2 separate columns with your values you should then be able to easily subtract them in an adjacent cell.
This is a little weird for an excel file. I am going to make an assumption that your data in column A is formatted as "Text" because otherwise it would be calculating the value. I also assumed that there is a space between the numbers and the /. So with those assumptions in mind you could have this function in column B to get your result.
This example is for Row 1 of course but you simply copy down for the other rows accordingly
=(RIGHT(A1,LEN(A1)-FIND("/",A1)))-(LEFT(A1,FIND("/",A1)-1))