Excel - How to SUM the results of LEFT? - excel

In row 2, I used =LEFT(B1,(FIND("/",B1,1)-1)) to get the 288 and ‭‭‭‭233‬‬‬‬. But when I tried to =SUM(B2:C2), it returned a 0. How do I SUM the results of LEFT()?

When you use LEFT() function then it returns result as string (not as number). So, you can not sum string. You need to convert string to number. You can use below formula
=LEFT(B1,(FIND("/",B1,1)-1))*1
Or use
=--LEFT(B1,(FIND("/",B1,1)-1))
Then sum output.
You can directly sum lefts before / by following formula.
=SUM(--LEFT(B1:C1,SEARCH("/",B1:C1)-1))

force the 288/233 to a number. the easiest way is =LEFT(B1,(FIND("/",B1,1)-1))+0

Related

Use max() and left() in the same command

I have data that looks like this and the format of the values is always the same.
entries
12aa
39aa
45ba
18ac
51cc
I want to get the max integer from the column without a helper column.
In this example, the formula would return 51.
If the format is always the same, as you show, with two digits and two alphabet, then simply:
=MAX(--LEFT(myRange,2))

Returning a specific value from a string

2.375;26.375;0.743|98.375;26.375;0.743|98.375;2.375;0.743|2.375;***2.375***;0.743|2.375;26.375;0.743555
I'm trying to return the second value equaling 2.375 after the 3rd "|". What's the best way to do this?
Thanks!
Asuming the string is in cell A1 (and the numbers are always 5 chars in length), the following formula will work:
=MID(A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1,5)
OR - to handle any length number you can do this:
=MID(A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1,FIND(";",A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1)-FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)-1)
This formula will bring the second number after the third | regardless of size.
=--TRIM(MID(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A1,"|",REPT(" ",999)),3*999,999)),";",REPT(" ",999)),999,999))
We can easily make this formula dynamic:
=--TRIM(MID(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A4,"|",REPT(" ",999)),(C1-1)*999+1,999)),";",REPT(" ",999)),(C2-1)*999+1,999))
This will allow you to specify the group and the sequence in that group to return the desired number.

Excel: Median of even number of values with a condition

When I calculate the median of even numbers for e.g 1,2,3,4,5,6,7,8.. i want the return value to be 5 i.e. the higher value of the two middle values and not the average of 4 & 5. Please help
I don't have Excel, so I can't try it, but I think you should be able to accomplish this with a combination of the LARGE function the COUNT function, and the TRUNC function. For example, if the numbers you are working with are in cells A1 through A8, you should be able to find the answer you want, though technically it's not the median, with the formula
=LARGE(A1:A8,TRUNC(COUNT(A1:A8)/2))
Edit
=LARGE(A1:A8,TRUNC((1+COUNT(A1:A8))/2))
If you know you will always be working with an even number of entries, the call to TRUNC could be omitted.
With data in column A:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),ROUNDUP(MEDIAN(A:A),0))
EDIT#1:
Consider the array formula:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),MIN(IF(A:A>MEDIAN(A:A),A:A)))
If the number of values is odd, return the median. If the number of value is even, return the smallest value greater than the median.
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
This approach does not require the data to be sorted.
EDIT#2:
This array formula appears to handle Ron's case:
=IF(ISODD(COUNT(A:A)),MEDIAN(A:A),MIN(IF(A:A>=MEDIAN(A:A),A:A)))
It returns the smallest value greater than or equal to the median (for the even case)
But I don't know if this is what the Poster wants.
=LARGE(A1:A9,INT((COUNT(A1:A9)/2)+0.5))
you can use Roundafter the Median
in your case you can type: =ROUND(MEDIAN(B4:I4),0)
lets say that the given range is from B4 to I4 from 1 to 8.

Excel - Return the first negative number of a column

I'm using Excel 2010 and I'm looking for a way to return the first negative number of a column. For instance, I have the following numbers distributed in a column:
1
4
6
-3
4
-1
-10
8
Which function could I use to return -3?
Thanks!
This could be interpreted two ways... If all the numbers are in a single cell (one column) as a string, the MID function can be used. If the numbers are in A1, a formula that could work is this:
=VALUE(MID(A1,SEARCH("-",A1),SEARCH(" ",A1,SEARCH("-",A1))-SEARCH("-",A1)))
If the numbers are each in their own columns (in my example, A3:H3), a different technique must be used:
{=INDEX(A3:H3,1,MATCH(TRUE,A3:H3<0,0))}
Don't type the { } - enter the equation using CTRL+SHIFT+ENTER.
In each case, the formula will return the number -3, which is the first negative number in the series.
Another possibility, avoiding the array formula (which are a big source of performance issues):
=LOOKUP(1;1/(M2:M15<0);M2:M15)
(I assume your numbers are in the M2:M15 range).
This will return the first number matching the "<0" condition. You may use any other condition, including text comparisons.
You may also extract the value of another array corresponding to the matching cell:
=LOOKUP(1;1/(M2:M15<>"OK");T2:T15)
In this example, the first cell containing another string than "OK" will be searched for in the m2:m15 array and the corresponding value in array t2:t15 will be returned.
Please note that the usage of the lookup function should be avoided whenever possible (but in this case, it's very handy !)
(I got the original inspiration for this answer from this post)

Excel sumproduct with condition

I want to SUMPRODUCT to ranges but only if there is no 0.
tried =SUMPRODUCT(--(CN12:CN16="<>0");I4:I8) but the results gets 0,
i have to ranges: CN12:CN16 and I4:I8, and CN12:CN16 can sometimes contain zeros. then i do not want to take that into the calculations and multiply with the value in I4:I8.
Any suggestions
Use this formula to get the SUMPRODUCT:
=SUMPRODUCT(CN12:CN16, I4:I8)
This evaluates AS:
=CN12*I4 + CN13*I5 + CN14*I6 + CN15*I7 + CN16*I8
So if one of the values equals to 0 that specific product equals to 0, and the rest of the products add to the total.
Here you have a REFERENCE to evaluate if any of the cells in your range equals with zero.
Do you actually want to use CN12:CN16 values in the calculation or are they simply a criteria range? In SUMPRODUCT you don't need the quotes so this might be what you need -
=SUMPRODUCT(--(CN12:CN16=<>0);I4:I8)
although SUMIF will get you the same thing more easily
=SUMIF(CN12:CN16;"<>0";I4:I8)
So solved it like this: =SUMPRODUCT(CN13:CN17;$I4:$I8)/SUMIF(CN13:CN17;"<>0";$I4:$I8)
As some of you wrote SUMPRODUCT gets zero if there is a zero in a list and then i check that list again in the SUMIF when i divided with the I4:I8. Maybe I was a little unclear in my description of the problem.
Thanks for your help.

Resources