I have a sumifs formula with a filter range on a column with a year. Sometime this year is formatted as a number, other times it is formatted as text.
How can I make my sumifs formula flexible enough to handle both years formatted as numbers and as text?
For example, this formula returns incorrect results when passed a year formatted as text:
=SUMIFS(C3:C6,B3:B6,"<>2016")
"Text that looks like a number" (whether in the form '2016 or ="2016") can easily be turned into a "number" by adding 0 to it.
Try this, which should yield the correct result regardless of whether the B3:B6 range is a number or text that looks like a number:
= SUMIFS(C3:C6,(B3:B6)+0,"<>2016")
EDIT
You may have to use SUMPRODUCT here instead, e.g.
= SUMPRODUCT(C3:C6,(((B3:B6)+0)<>2016)+0)
Assuming you are not using the ' prefix, mentioned by Jeeped, one way to do it is:
=SUM(C3:C7)-SUMIFS(C3:C7,B3:B7,"2016",B3:B7,2016)
Related
I'm wondering if there's a shortcut to the following.
I have a product form that customers will fill out and I need the formula to format the part numbers they enter correctly. If it doesn't their entry doesn't match the products list.
Below are the variety of text/number/other variations...
Excel Columns/ Rows Example
101
7-2009
7-5601-RT
G-2121
5728B
PI-PIXES
I got all but the last one working with this formula:
FORMULA1
=AND(SUMPRODUCT(--ISNUMBER(--MID(B40,ROW($1:$9996),1)))<LEN(B40),MIN(FIND({0,1,2,3,4,5,6,7,8,9},B40&"0123456789"))<=LEN(B40))
I also have to keep it in .xls format.
Basically, I have one column that checks this above and it returns TRUE/FALSE.
I have another formula that checks for text:
FORMULA2:
=IF(I40=FALSE,"NUMBER", "TEXT")
The final column TESTS FOR TEXT/NUMBER.
FORMULA3:
=IF(J40 = "NUMBER", VALUE(B40), B40)
PI-PIXES is flagged as number because of the dash(hyphen).
Without any other option, I'm considering adding a third column to find TEXT with hyphens. I would then change FORMULA3 check if both if column 1 = TRUE+column 2 = TRUE and column 3 = TEXT but this is getting complicated and I'm wondering if there's a shortcut.
I think this does it:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IFERROR(VALUE(B40),B40))
If there are hyphens, it returns the B40 unchanged, eliminating dates. Otherwise, it handles it as a normal Value conversion with IFERROR.
This should work for older versions of Excel:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IF(ISERR(VALUE(B40)),B40,VALUE(B40)))
Or even this:
=IF(ISERR(FIND("-",B40)),IF(ISERR(VALUE(B40)),B40,VALUE(B40)),B40)
I am trying to use the =COUNTIFS formula to track incoming post. Column B is the date of incoming post, Column E is the date the post is worked.
I want to count the number of rows where column B is less than today’s date and column E is blank.
I am using the formula below however it is giving me a return of 0 where it should be thousands.
=COUNTIFS(Invoices!B:B,"<Today()",Invoices!E:E,"")
Based on an answer I got here:
Excel: CountIf Quandry
I also tried formula below but again I am getting a 0 return.
=SUMPRODUCT(Invoices!B:B = "<Today()")*(Invoices!E:E="")
Finally I tried both formulae with much smaller ranges but again to no avail.
Appreciate any insights you may have
Thanks
The below formula will work, but you'll need to change the ranges to reflect your data set and maybe worksheet names.
The key to the below is combining the Today() function with the less than operator "<" by using an ampersand "&"
You also need to test column E for a blank value which is represented by blank quotation marks ""
=COUNTIFS(Invoices!B:B,"<"&TODAY(),Invoices!E:E,"")
You need to keep the TODAY() function outside of the quotation marks and concatenate it with the lesser than symbol. Try this:
=COUNTIFS(Invoices!B:B,"<"&TODAY(),Invoices!E:E,"")
Using Excel I am using a VLOOKUP where the lookup_value contains a formula that generates the string that should be searched. The formula:
=VLOOKUP(MID(A2,2,5),Sheet2!A:B,2,0)
All results come back with #N/A, yet if i substitute the MID() function with the value it generates the VLOOKUP functions fine.
Example data:
Sheet1
$#00001#
$#00002#
Sheet 2
00001 | Hello
00002 | World
The 00001 in sheet2 is actually a 1 in a cell that has been formatted as "00000" to display leading zeroes. This does not alter the raw underlying value of 1. You will need to convert the MID result to a true number with a double unary like,
=VLOOKUP(--MID(A2,2,5),Sheet2!A:B,2,0)
You cannot lookup text-that-looks-like-a-number in a column of true numbers regardless of how the true numbers are formatted for display.
Tip: Unless you manually change the cell alignment, text is left-aligned by default; numbers are right-aligned by default. This is a quick visual check that can prove the above scenario.
i agree with Jeeped's answer. however, looks like if $ was a literal, formula should actually contain
MID(A2,3,5)
as 00001 starts at position 3.
Formatting the column A in Sheet2 as Text is also a solution.
P.S. i am writing as answer since i was unable to comment on the question instead.
I have rows containing every Monday and Sunday in an entire year, (with variations on when a month starts and ends) like so,
11/05/2015 18/05/2015 25/05/2015 01/06/2015 08/06/2015
17/05/2015 24/05/2015 31/05/2015 07/06/2015 14/06/2015
However these are in the date format, and I need them in a text format, but so they still read in the dd/mm/yyyy format, not like 42125.
Further up my document, each column header should read dd/mm/yyyy-dd/mm/yyyy using each of the dates shown in my first example, and I was hoping to achieve this using the formula =A30&"-"&A31 and so on. So the desired outcome should read,
11/05/2015-17/05/2015 18/05/2015-24/05/2015
11/05/2015 18/05/2015
17/05/2015 24/05/2015
However using the =cell&cell formula im left with
42135-42141 42142-42148
11/05/2015 18/05/2015
17/05/2015 24/05/2015
I have to create these headings for 2 years worth of dates, and trying to avoid typing every heading out manually, is there a way to achieve this?
Use the TEXT function which comes with Excel.
Assuming cell A1 has "11/05/2015", use the following formula in cell B1:
B1=TEXT(A1,"dd/mm/yyyy")
This takes care of the first part of your question. For the second part, you can use the CONCATENATE function. Assuming that B1 and B2 contain dates as text, you can join them together using the following formula:
=CONCATENATE(B1, "-", B2)
Try converting those values to text before concatenating:
=TEXT(A1,"dd/mm/yyyy")&"-"&TEXT(A2,"dd/mm/yyyy")
You need to break them down like so:
=DAY(A3)&"/"&MONTH(A3)&"/"&YEAR(A3)&"-"&DAY(A4)&"/"&MONTH(A4)&"/"&YEAR(A4)
I am assuming here your data start from cell A3
Assuming headings in row 1 and dates in rows 3 and 4 this will work:
=TEXT(A3,"dd/mm/yyyy")&TEXT(A4," - dd/mm/yyyy")
without having to concatenate " - "
I have an Excel formula reading data from a column. The data in that column is sometimes a date-like format, such as "10-11". Despite the fact that I've ensured that column is text formatted -- and all values display correctly as plain text, not reinterpreted as dates -- the formula is basically reinterpreting them as dates in the reference.
I need a way to force the formula's cell reference to interpret the cell as text. I tried TEXT(A1, "#") but it doesn't work -- it gives the numeric value of the date.
Brian Camire's answer explains why, but here's a worksheet function that will work for you. Note that you have to create that numeric array in it based on how long the longest string will be. It's an array formula, so when you first enter it you have to hit CTRL-SHIFT-ENTER, then you can click and drag it down the column.
=LEFT(A1, MATCH(FALSE, ISNUMBER(VALUE(MID(A1, {1,2,3,4,5}, 1))),0) - 1)
Short answer: When referring to number-like (or date-like) text values in a formula, don't use them in a place in the formula where Excel is expecting a number.
Long answer: Even if the source column is formatted as text and the values in the source column are truly entered as text (and not numbers, including dates), Excel may automatically convert text values to numbers (including dates) when you reference them in a formula if you use them in a place where Excel is expecting a number (or date).
For example (assuming US date formats), in a blank worksheet:
Set the format for column A to Text.
In cell A1, enter the value 10-11.
In cell B1, enter the formula =T(A1). The T() worksheet function returns the supplied value if it is text. Otherwise, it returns an empty string. The result of the formula in cell B1 should be 10-11, indicating that the value of A1 is text, not a number or date (in which case the result would be an empty string).
In cell C1, enter the formula =A1.
In cell D1, enter the formula =T(C1). The result should also be 10-11, indicating that the value of the formula in C1 is text, not a number or date. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and have Excel treat it as text (which is what you want).
In cell E1, enter the formula =A1+0. The result will be 40827. This is the numeric value of the date October 11, 2011. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and Excel will automatically convert it to a number (which is what you observed) if you use it in a place (like on either side of the + operator) where Excel is expecting a number.
To insert a value into a cell and have it not be auto-formatted, and just treated as text, you can enter it like this:
=("cell data")
eg:
=("+1 3456789")
When you use &"", Excel converts the results of a formula to text (like *1 would convert to numbers).
Thus, you can use this formula:
=TEXT(A1;"jj-mm")&""
If you put a single quote in front of the text in the cell, it should be represented as text on all references:
'10-11
Just add zero to the input!
I was having a similar problem where I had a list of numbers with a text prefix (like FOO-1, FOO-25, FOO-979) but I just wanted the number part (1, 25, 979) so I could run another formula off of that. I was using SUBSTITUTE to replace the text portion with blank, but my other formula using these numbers was coming up with bogus results. I ended up making my formula like this:
=SUBSTITUTE(B1:B10,"FOO-","")+0, and now the ISNUMBER is saying TRUE where before it was saying FALSE.
In my case, I have a form worksheet that is used by dealers to ad parts and have it calculate the final cost; it references a locked "products" sheet. The problem is that I had no way of controlling what they entered.
Products can be like:
101 = A true number
7-2009 = Reads as date
7-5601-RT = TEXT/NUMBER reads as both number or text (NOT SOLVED YET)
CP6072CD = reads as plain text
I have most of this figured out; the only one that isn't is the one that reads as both text/Number.
In case anyone is looking for a similar solution, i did the following:
I created three additional columns to test and display the three different cases: "NUMBER", "DATE" , "TEXT".
DATE: =NOT(ISERROR(DATEVALUE(B42)))
ISOTHER: =(ISNUMBER(--(MID(B42,ROW(INDIRECT("1:"&LEN(B42))),1))))
NUMBER: =ISNUMBER(B42)
NUMBER/TEXT: =NOT SOLVED YET
I42 = DATE
J42 = NUMBER
K42 = OTHER
L42 = TEXT
M42 = THE RESULT OF THE QUERY BELOW
=IF(AND(I42 = FALSE, J42 = FALSE, K42 = TRUE), "NUMBER", IF(AND( I42 = TRUE, J42= FALSE, K42=TRUE), "DATE", "TEXT"))
This (ABOVE) tests all the true/false results and depending on what the value turns out to be, I format each of them using:
ISNUMBER = VALUE(B42)
DATE FORMATTED AS B42*1
ELSE TEXT - AS ORIGINAL
=IF(M42 = "NUMBER", VALUE(B42), IF(M42 = "DATE", B42*1, B42))
So now I just need to figure out how to test if something is both text and number because the 7-5601-RT tests out as the same as number: "FALSE, FALSE, TRUE, TRUE"