How to use formula on numbers extracted from a text data - excel-formula

An elementary example of my problem with an Excel workbook (French version):
In A1: EUR 53,00
In A2 : EUR 12,50
In B1 the formula : =DROITE(A1;NBCAR(A1)-4) yields 53,00
In B2 analogously : =DROITE(A2;NBCAR(A2)-4) yields 12,50
Now, in B3, I use the formula: =somme(B1:B2) then it yields 0,00
Similarly, if I use the formula: =produit(B1:B2) it also yields 0,00
However : = B1+B2 yields correctly 65,50
Seems that formulas cannot compute, or they are interpreting the integers as strings (?). Of course, I've tried various ways to format cells so that they are integers, with no avail.
Any idea to solve this will be highly appreciated.

When you perform your first operation it is a string operation. You are pulling a string from a portion of a string. In other words you're pulling a portion of text from a bigger piece of text. While your text may look like numbers, they are still numbers stored as text.
When numbers as text and booleans TRUE and FALSE are sent through a math operation they are converted to number automatically by the system. Unfortunately Sum (Somme) and Product (Produit) are both functions, not math operators. Some functions may be set up to deal with numbers as strings, others are not.
To solve your situation you have a few options. After taking your number as a string, you can send it through a math operation that will not affect its value such as *1, /1, +0 or you could use the VALUE function. Try the following adjustments and see if they work for you:
DROITE(A1;NBCAR(A1)-4)*1
CNUM(DROITE(A1;NBCAR(A1)-4))

Discovered that one can use CNUM to tell the "text" is a "number".
Thus use in B1 : =CNUM(DROITE(A1;NBCAR(A1)-4)) and similarly in B2.
The functions now apply correctly to these numbers.
This is inconsistent since =B1+B2 was working : in that case B1 and B2 were correctly recognized as numbers. But at least the above repair works.
It is Microsoft, what can you expect…

Related

(Excel) Formula to Sum numbers contained in a String (w/o using 'Evaluate')

I've searched the web but can't wrap my head around it.
Problem: Individual cell containing string of one or more numbers in percent. If there are multiple numbers, they are separated by a linebreak CHAR(10). Example. cell A1 has this value:
96%
4%
3%
Wanted outcome: Sum up of the numbers irrespective of how many there are. In the above example, result should be 103%.
Challenge: Must be done via a simple single-cell formula, macros (i.e. '=Evaluate') not possible
Here my formula so far:
=TEXT(IF(ISBLANK(A1),0,
IF(LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))>0,
(SUMPRODUCT(--TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1, ",",""),CHAR(10),REPT(" ",100)),{1,100},100)))),
A1)
),"0.00%")
Where the part in questions is:
SUMPRODUCT(--TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1, ",", ""),CHAR(10),REPT(" ",100)),{1,100},100))))
Which also contains a fail-safe in case a user adds a comma as a separator in addition to the linebreak.
The formula however will always only sum the first two numbers in the string, in this case 96% and 4%... I must admit I'm not comfortable with MID to understand what I am doing wrong.
Thanks in advance!
EDIT: SOLUTION
=SUMPRODUCT(FILTERXML("<h><e>"&SUBSTITUTE(SUBSTITUTE(A1,",",""),CHAR(10),"</e><e>")&"</e></h>","//e"))
Assuming you're using at least Excel 2013, then this must be entered as an array formula (unless you have dynamic arrays)
=SUM(FILTERXML("<h><e>"&SUBSTITUTE(SUBSTITUTE(A1,",",CHAR(10)),CHAR(10),"</e><e>")&"</e></h>","//e"))

Excel Numerical Precision Issue with COUNTIF: for few numerical values counting X as being larger than X itself

While COUNTIF() for most numerical arguments rightly answers 0 when asked the triviality how many values among X are larger than X (i.e. COUNTIF(X,">X") yielding 0), for some weird numerical values of X, COUNTIF(X,">X") yields 1, thus wrongly claiming X would be larger than X.
Consider a constant value to be in Cell A1 (the X above).
Consider Cell A2 to count all values in A1 only (i.e. Range A1:A1), which are larger than A1 itself:
=COUNTIF(A1:A1,">"&A1)
For "normal" (i.e. most) values in A1, this rightly yields 0.
For some specific values, call them "weird" values, I find it to return 1, however.
A way to create an example of such a weird number manually is:
=564.777008837525+(564.777008837526-564.777008837525)/2 as value for A1
Use instead essentially nearly any other value for A1, and you find COUNTIF instead to work.
I reckon a bug related to numerical precision when calculating the COUNTIF result.
Is there any genuine fix to this? Or instead only workarounds?
Excel Version: Excel 2016
Note:
This is not related to the special case of A1:A1 to be a 'collapsed' 1-cell-only range. Use larger ranges, filled with different values, and the same weird behavior obtains still.
Also, it does not matter whether the criteria parameter contains a reference to the "weird" value in the range parameter, or instead to an independent copy of that value in some other cell.
When you manually copy-paste the numeric form of the weird' value from the cell, and use the manually copied version, the problem disappears. I.e., when copying the value manually you seem to copy a slightly different numerical value; Excel does not seem to provide you the full precision of the number when giving you the numeric value in digits form; it seemingly errs instead on the side of showing less rather than more precision in the decimal number than what is truly stored in its binary format.
Other weird values leading to the same wrong counting behavior exist.

COUNTIF dependend on cell format and input type?

Question: Is the COUNTIF function working inconsistent with different data types and cell formats?
The situation:
Column A contains manually created numbers (to be used in SAP). The numbers are 18 characters long, don't contain any non digit chars. The cell format has to be Text as we would face more issues down the line if it wouldn't. If I apply the formula =COUNTIF(A:A;A2) the result is as shown in column C. However this obviously not the correct result.
Another example with "real" test data from a system extract:
The issue here is, that the COUNTIF function sometimes returns the correct result, sometimes a wrong result. I cannot figure out why its working the way it does.
Also I did not find any satisfying result somewhere else on the Internet. If I missed something, please let me know.
As a side note: If I transfer the data into a PIVOT table it always shows the correct results.
Problem:
This will most likely be due to floating point errors.
Excel's COUNTIF function will try to handle these values in A column as numbers. Because Excel uses IEEE 754 specification on how to store and calculate floating-point numbers, Excel therefore stores only 15 significant digits in a number, and changes trailing digits after the fifteenth place to zeroes. Source.
For example:
541235479876536549 will become 541235479876536000
541235479876536550 will become 541235479876536000
541235479876536551 will become 541235479876536000
541235479876536552 will become 541235479876536000
That would mean your values are 3 digits too long to be handled accurately. In this example, the unique values will all be counted 4 times using COUNTIF.
Removing the last three digits from your string should therefor make the COUNTIF behave as expected. However, this will still give you unwanted results as you don't want to mess with the original data.
Solution:
If using a pivot table (which probably works as it should pick up the data as text) is not what you want, maybe you can use:
=SUMPRODUCT(--(A$2:A$11=A2))
Note: On a large dataset, array-formulas might slow down your
workbook significantly!
Furthermore, COUNTIF is not the only function that would suffer from this behaviour. The scope of this problem included functions like SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, and AVERAGEIFS. Source

How to add cells with mix of 6 to 8 decimal places together

Because of floating point values, I cannot add a string of cells that contain values such as:
0.08178502
0.09262585
0.13261762
0.13016377
0.12302067
0.1136332
0.12176183
0.11430552
0.09971409
0.125285
Even if I try adding the first two through a sum formula or auto sum through selecting them, excel spits out an error. I have googled this like crazy and tried to change number formats. Is there a function that can allow me to add this information ?
Screenshot:
The spreadsheet is available on my Dropbox.
Those numbers are all preceded by a NBSP (Char Code 160). So, in order to sum them, you have to remove that. Many solutions. Here's one:
=SUMPRODUCT(--SUBSTITUTE(A1:A18,CHAR(160),""))
If a formula like:
=A1+A2+A3+A4+A5+A6+A7+A8+A9+A10
produces:
#VALUE!
then your "numbers" cells contain non-visible characters.
They must be removed before the formula will work.
If the cells contain text strings and not actual values you will need to convert the text to numeric values before performing any calculations. The function "=value(cell)" will bring the numeric value.
e.g.: A1 contains "000.12345678" (or some other non-numeric presentation of numerals)
In cell B1 type: =value(a1)
Cell B1 now operates as the real number 0.12345678
Oddly enough, the fact that it said 0.xxxxx in all numbers vs. .xxxxx is what the issue was. I'm just sharing that for folks who google/search and have same issue.
All I had to do was select that whole row and do a search in replace for "0." and make it just "." and now my numbers were usable in equations. For some reason the adjustment of formating as many searches suggested wasn't working

Excel Getting bad text to column results - need the 10s digit number out of these cells

So for these items I want,
2,2,6,2,6,8
cells
21.00
22.00
68.00
821.00
67.00
86.00
I found an example that did
=MID(A1, FIND(".", A1)+1, 1)
but that does not work
I also thought of modding the value - but can't seem to get that to work either
suggestions?
Try the formula:
=RIGHT(INT(A1/10),1)
I should note that my formula returns the number as a string, whereas t_m's answer returns the number as a number. My string response will be converted to a numeric value by many, but not all, Excel functions, so which will work better will depend on what you want to do with the result.
Of course, mine could be converted to a number by various techniques:
=--RIGHT(INT(A1/10),1)
=VALUE(RIGHT(INT(A1/10),1))
etc
Formula from Excel 2013 using MOD function
=(MOD(F3|100)-MOD(F3|10))/10

Resources