=(Countifs(B:B;”*”;F:F;”<>*1”))
Why doesn't this work?
I want to count all the rows in the sheet, except the ones that has a number that ends with 1 in column F. It just count all the rows, even the ones in column F that ends with 1.
How do I exclude those?
edit
Some more information!
This is a sample of the data:
Could be up to 8000 rows some days. Column B always says "Independent instruction" so I'm using that as a base to count all the rows. Column F contain only numbers, or blank cells (meaning a number will be added later). I still want to count those rows as well (that's blank). It's just the rows that has a number in column F that ends with 1 that I want to exclude!
SUMPRODUCT gives a bit more flexibility for criteria that involve more than straightforward string-matching:
=SUMPRODUCT(--(LEN($B:$B)>0),--(RIGHT($F:$F,1)<>"1"))
The array formula:
{=COUNT(IF((F:F<>"")*(MOD(F:F;10)<>1);F:F))}
will count all non empty cells in the conditions of your question.
Don't forget to press Ctrl+Shift+Enter to place the formula.
Why doesn't this work?
Apart from the fact that you have transcribed it incorrectly (i.e. missing =, and smart quotes ”) the 'F' condition in quotes is a Text value, a formatting issue #BigBen has mentioned in connection with the 'B' values.
You say It just count all the rows so, syntactically corrected, your formula must be working on (a) all 'B's populated (with Text) and (b) all 'F's Numeric. As 1 and "1" are not the same, none of your entries in ColumnF will be excluded by your attempt (none end in "1", though presumably some do end in 1).
#Pspl's A works because its condition (for the 'F's) is based on MOD (applies to Number format values) and #jsheeran's A (my preference) because RIGHT is a string function that returns Text format even from a Number format value.
Put another way, with say 1 in F1, =F1="1" returns FALSE (so =F1<>"1" and =F1<>"*1" return TRUE - that would not suit you) whereas =RIGHT(F1)="1" returns TRUE (or, to suit you, RIGHT(F1)<>"1" returns FALSE).
You can try to use a combination of SUM and IF. Remember to adjust the formula to match your Excel formatting, i.e. replace commas (,) with semicolon (;).
This is an array formula (enter with Ctrl+Shift+Enter)
=SUM(IF(MOD($F$2:$F$25,10)<>1,1,0))
Result (updated with your data set):
When pasting the image into merged cells, the error looks like that:
So you need to make sure the formula is pasted into a single (not merged) cell.
Array formula for values greater than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25>1000),1,0))
Array formula for values less than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25<1000),1,0))
Example:
Related
I have a spreadsheet that I track my hours. Each cell initially is populated with a formula, i.e. =IF(WORKDAY(B24-1,1,holidays2019)=B24,OFFSET(C24,-1,2),0)
and then as the month progresses I enter my actual time.
In the following excerpt all values through 5/10/2019 are entered.
The formula =SUMIF(C5:C19,NOT(ISFORMULA(C5:C19))) shows zero. I do not understand why this does not work.
I appreciate any help! Column B in my spreadsheet corresponds to the dates shown below and Column C to the time entries.
Expected Result: 48.9
=SUMPRODUCT(J6:J20,--NOT(ISFORMULA(J6:J20)))
The key to this solution is the -- in front of the NOT(). A boolean that is processed by a math operator gets converted to 1 or 0. --, +0, -0, *1, /1 would have all worked to do the conversion. So now you wind up with an array of values you may want to sum being multiplied by an array of 1 and 0 to indicate the ones you want. The 1 are manual entry and the 0 are your formulas entries.
Now SUMPRODUCT performs array like calculations. As a result avoid using full column/row references inside it or you will wind up with a lot of excess calculations. Adjust the ranges in the answer to suit your needs.
Here's the MSDN definition of the Criteria in =SUMIF
criteria Required. The criteria in the form of a number, expression,
a cell reference, text, or a function that defines which cells will be
added. For example, criteria can be expressed as 32, ">32", B5, "32",
"apples", or TODAY().
Important: Any text criteria or any criteria that includes logical or
mathematical symbols must be enclosed in double quotation marks (").
If the criteria is numeric, double quotation marks are not required.
So, the reason, why your SUMIF returns 0 is, because none of the cells match the criteria, as they return a number and meanwhile they expect FALSE
Another issue here being, that the ISFORMULA will return TRUE, even when a range contains a single formula while all the rest has none. So basically you need to drag the formula down for each cell individually and sum them up only when a value is TRUE
Starting from cell D1:
=ISFORMULA(B1)
And then you can simply sum them up with the formula you provided.
=SUMIF(D1:D16,TRUE,C1:C16)
Obviously, you can hide the column D to make it more aesthetically pleasing.
Your formula fails because the criteria you're matching against, is TRUE/FALSE. Obviously the values in C5:C19 don't contain any booleans, so the sum is 0.
To solve this, you can add the correct criteria in cell D5 and below: =ISFORMULA(C5)
Then use =SUMIF(D5:D19,FALSE,C5:C19) to sum the values in column C.
I have two lists as follows, Column A and Column D:
I would like to find all cells in Column A that do not contain a value from Column D.
For instance, A1 should be 0 because it contains the values 'a', 'b', 'c' and 'd' - all of which are in Column D.
A2 should be 1 because it contains the value 'h' - which is not in Column D.
My formula so far is very simple:
=COUNTIF(D1:D7,"*"&$A1&"*")
I'm guessing I could split the values in Column A to check, but am not too sure how.
I would like to avoid any VBA if possible.
Your question is not entirely clear to me, so far as what you want for results under different circumstances.
Your formula will return an array of values, so you need to account for that. The array consists of a 1 or a 0 depending on whether the character matches a letter in the D1:D7 range.
If you want to return the number of letters in your column "A" item that do NOT match an entry in Column "D", then try:
=LEN(A1)-SUMPRODUCT(COUNTIF(A1,"*"&$D$1:$D$7&"*"))
The SUMPRODUCT functions sums the array that the COUNTIF function is returning.
If you want something else, you will need to be more specific.
Cross-tabular layout
Using your logic, just with different layout of the data, you can achieve this:
Formula for B4 is: =COUNTIF(B$3;"*"&$A4&"*")
Formula for B1 is: =B2-SUM(B4:B10)
This is more along the lines of a comment, but I don't have enough reputation yet for comments.
The accepted answer from #ronrosenfeld will not work if the string in Column A contains repeated characters from the list in Column D. For example, if A1 contains "abca," it will return 1 rather than 0 because the array entry for "a" is 1 rather than 2 (it can only be 0 or 1).
So be aware that it only works if the letters are not repeated.
I cobbled a formula together based on some array magic I found by #ronrosenfeld here. (It seems so appropriate that Ron already got credit for answering this question, as my answer is a modification of another of his.)
The following formula works for any length of string in Column A and for any combination of letters including duplicates. It is entered as a regular formula:
=IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1)
You just enter it in B1, then copy it down as far as you like.
It works for strings of any length. If a cell is blank, it returns 1 because there is nothing there that appears in the list. If you want 0 for a blank cell, you can adjust the formula for that situation. Brute force approach:
=if(isblank(a1),0,IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1))
I have two tables, table1 and table2. I execute VLOOKUP function in order to fill in 3 columns from table2 into table1.
For some reason, the formula doesn't work for the first row, and doesn't find the exact match from table2 even though it exists.
I made sure that both columns (for comparison) have the same format (General) and there is no extra spacing. Same conditions also apply for the rest of the records, and it works there properly.
table1 - you can see the missing matches for the first row.
table2 - you can see the match does exist, but it is not reflected in table1.
Is there any other reason why VLOOKUP can't find a match for a specific record?
Try directly evaluating equality for the two cells that you believe are equal, for instance if A2 is the value you are looking up and Sheet2!A100 is the value you think should match try this in a cell:
=(A2=Sheet2!A100)
If that returns false then you know that there is some formatting issue or error in your vlookup.
Also try Formulas / Evaluate Formula ribbon command to step through your vlookup in case that highlights something wrong.
Okay - Here's a doozy of a use-case. VLOOKUP and INDEX-MATCH were returning #N/A for values that were "apparently" equal. Cleaned my data with =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) and that didn't work.
Then, I compared two cells that looked like they had matching values and they evaluated to FALSE (A1=B1 resulted in FALSE).
Then, as a last resort, I code checked each ASCII value for each character in the two cells and I found that the "-" in one cell was different from the "-" in the other cell. The first cell has the ASCII value 63 and the second cell had the ASCII value 45 for what looked like was the same "-". Turns out that 63 is a "short dash" and 45 is your standard dash or minus symbol.
The way to evaluate the ASCII codes for each character in a string is to combine the CODE function with the MID or RIGHT functions after testing the cells for length using the LEN function.
Examples:
LEN(A1) should equal LEN(B1)
For the first character in each cell:
CODE(A1) Code defaults to the first character on the left
CODE(MID(A1,2,1) yields the ASCII for the second character
CODE(MID(A1,3,1) yields the ASCII for the second character
and so on
If you have a lot of characters you can post an integer sequence next to your CODE-MID function and point the position argument to the related integer and just copy down or across
Or
You can look for the weird non-numeric character and just test that one for both cells.
Have observed scenarios like this where direct comparison fails (e.g. formula =A1=B1 resulted in FALSE) and yet length =LEN(A1)=LEN(B1) and letter by letter ASCI comparison (=CODE(A1,1,1), =CODE(A1,2,1), =CODE(A1,3,1), etc.) shows no difference.
What worked was to adjust the format of the lookup value inside the VLOOKUP.
e.g.
=VLOOKUP(A1, ARRAY, COL_NUM, FALSE) -> =VLOOKUP(TEXT(A1, "000"), ARRAY, COL_NUM, FALSE)
Here's an issue I encountered: my VLOOKUP formula returns the correct value (1) if I type in the value-to-look-up (1.016) directly in the formula, shown in cell F54.
However, if I referenced a value in column A as the value-to-look-up, the formula returned #N/A, as shown in cell F55.
(I was actually trying to VLOOKUP the current row's A value plus 0.015, i.e. VLOOKUP(A54+0.015, $A$3:$B$203, 2, FALSE))
Yet if I use the ROUND function, then the VLOOKUP formula works, as shown in F56.
I recently encountered the same issue and resolved it by changing the vlookup formula to =VLOOKUP([value to lookup], [lookup table], [column to return in the lookup table], False). Setting the last input argument to "false" forces Excel vlookup function to perform an exact match.
I want to calculate the average over a range (B1:B12 or C1:C12 in the figure), excluding:
Cells not being numeric, including Empty strings, Blank cells with no contents, #NA, text, etc. (B1+B8:B12 or C1+C8:C12 here).
Cells for which corresponding cells in a range (A1:A12 here) have values outside an interval ([7,35] here). This would further exclude B2:B3 or C2:C3.
At this point, cells in column A may contain numbers or have no contents.
I think it is not possible to use any built-in AVERAGE-like function. Then, I tried calculating the sum, the count, and divide. I can calculate the count (F2 and F7), but not the sum (F3), when I have #N/A in the range, e.g.
How can I do this?
Notes:
Column G shows the formulas in column F.
I cannot filter and use SUBTOTAL.
B8:C8 contain Blank cells with no contents, B9:C9 contain Empty strings.
I am looking for (non-user defined) formulas, i.e., non-VBA.
From
https://stackoverflow.com/a/30242599/2103990:
Providing you are using Excel 2010 and above the AGGREGATE
function
can be optioned to ignore all errors.
=AGGREGATE(1, 6, A1:A5)
You can accomplish this by using array formulas based upon nested IFs to provide at least part of the criteria. When an IF resolves to FALSE it no longer process the TRUE portion of the statement.
The array formulas in F2:F3 are,
=SUM(IF(NOT(ISNA(B2:B13)), (A2:A13>=7)*(A2:A13<=35)*(B2:B13<>"")))
=SUM(IF(NOT(ISNA(B2:B13)), IF(B2:B13<>"", (A2:A13>=7)*(A2:A13<=35)*B2:B13)))
The array formulas in F7:F8 are,
=SUM(IF(NOT(ISNA(C2:C13)), (A2:A13>=7)*(A2:A13<=35)*(C2:C13<>"")))
=SUM(IF(NOT(ISNA(C2:C13)), IF(C2:C13<>"", (A2:A13>=7)*(A2:A13<=35)*C2:C13)))
Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered correctly, they can be filled down like any other formula if necessary.
Array formulas increase calculation load logarithmically as the range(s) they refer to expand. Try to keep excess blank rows to a minimum and avoid full column references.
You can get the average of your "NA" column values in one fairly simple formula like this:
=AVERAGE(IF(
(
($A$2:$A$13>=$F$2)*
($A$2:$A$13<=$F$3)*
ISNUMBER(B2:B13)
)>0,
B2:B13))
entered as an array formula using CtrlShiftEnter↵.
I find this to be a very clear way of writing it, because all your conditions are lined up next to each other. They're "and'ed" using the mathematical operator *; this of course converts TRUE and FALSE values to 1's and 0's, respectively, so when the and'ing is done, I convert them back to TRUE/FALSE using >0. Note that instead of hard-coding your thresholds 7 and 35 (hard-coding literals is usually considered bad practice), I put them in cells.
Same logic for your sum and your count; just replace AVERAGE with SUM and COUNT, respectively:
=SUM(IF((($A$2:$A$13>=$F$2)*($A$2:$A$13<=$F$3)*ISNUMBER(B2:B13))>0,B2:B13))
=COUNT(IF((($A$2:$A$13>=$F$2)*($A$2:$A$13<=$F$3)*ISNUMBER(B2:B13))>0,B2:B13))
though a more succinct formula can also be used for the count:
=SUM(($A$2:$A$13>=$F$2)*($A$2:$A$13<=$F$3)*ISNUMBER(B2:B13))
The same formulas can be used to average/sum/count your "blank" column. Here I just drag-copied them one column to the right (column G), which means that all instances of B2:B13 became C2:C13.
Here are my 2 columns
A B
Spain [EMPTY]
France Euros
Spain Euros
In another cell, I would like to write a formula that would write the currency of each country. like if I have:
C1=Spain, C2=France,
I would want to have
D1=Euros, D2=Euros.
I tried it with VLOOKUP, but it gave me
C1=[Empty], C2=Euros
Thank you very much for your time
As others have commented, VLOOKUP will return the first match it finds, thats why you get [EMPTY] for Spain.
You can work around this by adding an intermediate column. Lets assume you insert a column B with formula =IF(C1="","",A1) and copy down for all used rows.
Column D is Spain, France etc
Column E is now =VLOOKUP(D1,B:C,2,0)
IF you can SORT your columns, sort by Column A then by B descending (Z-A) then use the vlookup you're trying to use. THis will put the country with a value 1st so V-Lookup will return a vale instead of empty. When empty is returned, its becuase EVERY single instance of that entry in column A has an empty value. However if the entry in A has Multiple values, it will pick the first from descending order.
So do you have situations in which a entry in column A has multiple values beyond 1 currency and a blank entry?
However this has a pitfall in that the Order now matters so if data is added to this spreadsheet a reorder must occur each time.
I'm more a VBA than formula guy but this (horrible!) array formula will return the first non blank match
in D1 put
=IF(MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))>0,INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))),"no match")
and press Shift - Ctrl - Enter together
how it works
IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)) checks that A1 matches each of A1 to A6, and correspondingly whether B1 to B6 is non-empty.
If both these conditions are TRUE then the row number of these matches is placed in an array, if FALSE the formula returns zero. so the first array id {0,0,3,0,0,0}
If the MAX of this array is not zero then the formula returns this cell position from the B column using INDEX in INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)))
Else there is "no match"
I will shoot this to a formula genius called Barry Houdini to see how much he can shorten it
Enlarged sample (including a true blank result) below
I feel like a fraud here.....don't ask me any VBA questions!
I note that use of MAX actually means that your formula (and chris' amended version) actually gives the last non-blank match. You can also do that with a non-CSE LOOKUP formula, i.e.
=LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)
which will return #N/A if there's no match
for the text "no match" instead then, assuming formula returns text values you can use 2003 compatible
=LOOKUP("zzz",IF({1,0},"No match",LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)))
For first non-blank match you can use INDEX/MATCH in a similar way, i.e.
=INDEX(B$2:B$6,MATCH(1,(B$2:B$6<>"")*(A$2:A$6=C1),0))
confirmed with CTRL+SHIFT+ENTER