I want to writte an If function with the following condition:
80% > value then 0 point
85% > value >= 80% then 1 point
90% > value >= 85% then 2 points
95% > value >= 90% then 3 points
97.5% > value >= 95% then 4 points
value >= 97.5% then 6 points
This is what I wrote, but I got an error for cases < 97.5%. I don't know where I did wrong. Please help
" =if(value >=97.5%,6,IF(AND(value >=95%,value <97.5%,4,IF(AND(value >=90%,value <95%),3, IF(AND(value >=85%,value <90%),2,IF(AND(value >=80%,value <85%),1,0)))))) "
By restructuring your IFs, you can do away with the need to check the upper bounds of each band, and therefore the ANDs which are less efficient.
Please see the formula below where your value is in cell A1:
=IF(A1 >= 97.5%, 6,
IF(A1 >= 95%, 4,
IF(A1 >= 90%, 3,
IF(A1 >= 85%, 2,
IF(A1 >= 80, 1, 0)
)
)
)
)
P.S. You can add new lines in the Excel formula bar by holding Alt and pressing the Enter key. This allows you to format your formulas to make them easier to read.
Easy Updates With Reference Table
The solution above is fine, if it is a one off formula that won't change often. However, if you have the formula repeated in numerous places and may need to change the cut offs or points associated with them often, it will quickly become labourious and error prone to find and update all the formulas.
The answer to this is to keep the cut offs and points in a separate reference table (which could be kept on a hidden sheet) and use a formula to look up the number of points that should be awarded. That way, you only have to update the table, and not each formula.
=INDEX($E$2:$E$7,MATCH($A$1,$D$2:$D$7,1))
Related
I have a column of time data formatted like this: Machine_Usage
I want to make an IF statement that returns 1, 2 or 3 corresponding to first, second or third shift if the times fall between certain values.
I already tried many times but not worked, please help me.
I want to find the right formula/syntax that can solved this problem for length of use of the machine based on the shift.
This is a possible approach, but not an answer because the question needs clarification on how to handle the following situations:
The interval [Start, End] is not within a single shift. According to some input data, it starts in one shift and ends in another one.
When End corresponds to a day after Start. This only can apply for shift 3, but based on the data there is no such scenario
In cell F2 put the following formula (the result is spilled, no need to drag down the formula)
=LET(start, C2:C20, end, D2:D20, lkup, H2:J4, shift, INDEX(lkup,,1),
lkStart, INDEX(lkup,,2), lkEnd, INDEX(lkup,,3),
MAP(start, end, LAMBDA(ss,ee, LET(startI, INT(ss) + lkStart,
endI, INT(ss) + lkEnd,
result, FILTER(shift, (ss >= startI) * (ee < endI), "Shift not found"),
IF(ROWS(result) > 1, "Overlap", result)
)))
)
Here is the output:
As you can see based on the data issue mentioned before no shift was found for any of the rows. Probably after data clean-up or more clarification, the formula should return a more realistic result.
Even the Shift information is represented in hh:mm format (see the previous screenshot). The end date of the last shift corresponds to the next day. Therefore the numeric values associated with the hours are the following:
Shift Start End
1 0.25 0.58
2 0.58 0.92
3 0.92 1.25
The logic of the formula is based on the above settings.
I was trying to do a formula to see if I should or not not have a bet on something.
The formula divides two cells, then -1, then multiplies by 100 to get a percentage. If this percentage is greater to or equal to 10, I want it to say bet, if not, I want it to say Don't bet. Here is what I can't get to work now.
=IF(SUM((D27/C27)- 1) * 100) >= 10, "BET", "DON'T BET")
Your formula contains an error
=IF((SUM((D27/C27)- 1) * 100) >= 10, "BET", "DON'T BET")
^ You are missing a bracket here.
My formula is giving me unexpected responses.
=IF(I5+H5=0,"Paid","Due")
see below
H I J k
-£34.40 £34.40 £0.00 Due
Cell H is calculated with this
=(SUM(F5+G5))*-1
See correct output with exact same formula on same worksheet
=IF(I3+H3=0,"Paid","Due")
H I J K
-£205.44 £205.44 £0.00 Paid
Cell H is calculated he same
=(SUM(F3+G3))*-1
Any ideas why the top calculation not correct but the bottom one is.
This is most likely the floating point issue. You should not compare floating point numbers directly with = because computers can't store the full decimal places. Just like if you divide 1 dollar by 3, you end up with .3333333333333 cents, well if you add 3 of those you don't necessarily get back 1 dollar, but slightly less due to the "lost" 3333's at the end. The proper way to compare is using a Delta threshold, meaning "how close" it needs to be.
so instead of
if (a+b=c,"paid", "due")
you would do
if(ABS(c-(a+b))<.01, "paid", "due")
so in that case .01 is the delta, or "how close" it has to be. It has to be within 1 cent. the formula literally means "if the absolute value of the difference between c and (a+b) is less than 1 cent, return paid, else return due. (of course, this will say due if they overpaid, so keep that in mind)
you should always do this.
i need to know how can i exclude 0 from rows and get the MIN Value.
But also i need to exlude the F1 Cell.
Ex:
A B C D E F
1 0 18 20 0 150 = 18
but if i do this In excel with =MIN(A1,B1,C1,D1,E1) return 0.
Any help is appreciated.
Try this formula
=SMALL((A1,C1,E1),INDEX(FREQUENCY((A1,C1,E1),0),1)+1)
Both SMALL and FREQUENCY functions accept "unions" as arguments, i.e. single cell references separated by commas and enclosed in brackets like (A1,C1,E1).
So the formula uses FREQUENCY and INDEX to find the number of zeroes in a range and if you add 1 to that you get the k value such that the kth smallest is always the minimum value excluding zero.
I'm assuming you don't have negative numbers.....
Enter the following into the result cell and then press Ctrl & Shift while pushing ENTER:
=MIN(If(A1:E1>0,A1:E1))
Not entirely sure what you want here, but if you want to discount blank cells in the range and pass over zeros then this would do it; if a little contrived:
=MIN(IF(A1:E1=0,MAX(A1:E1),A1:E1))
With Ctrl+Shift+Enter as an array.
What I'm doing here is replacing zeros with the maximum value in the list.
if all your value are positive, you can do -max(-n)
Solutions listed did not exactly work for me. The closest was Chief Wiggum - I wanted to add a comment on his answer but lack the reputation to do so. So I post as separate answer:
=MIN(IF(A1:E1>0;A1:E1))
Then instead of pressing ENTER, press CTRL+SHIFT+ENTER and watch Excel add { and } to respectively the beginning and the end of the formula (to activate the formula on array).
The comma "," and "If" statement as proposed by Chief Wiggum did not work on Excel Home and Student 2013. Need a semicolon ";" as well as full cap "IF" did the trick. Small syntax difference but took me 1.5 hour to figure out why I was getting an error and #VALUE.
Throwing my hat in the ring:
1) First we execute the NOT function on a set of integers,
evaluating non-zeros to 0 and zeros to 1
2) Then we search for the MAX in our original set of integers
3) Then we multiply each number in the set generated in step 1 by the MAX found in step 2, setting ones as 0 and zeros as MAX
4) Then we add the set generated in step 3 to our original set
5) Lastly we look for the MIN in the set generated in step 4
{=MIN((NOT(A1:A5000)* MAX(A1:A5000))+ A1:A5000)}
If you know the rough range of numbers, you can replace the MAX(RANGE) with a constant. This speeds things up slightly, still not enough to compete with the faster functions.
Also did a quick test run on data set of 5000 integers with formula being executed 5000 times.
{=SMALL(A1:A5000,COUNTIF(A1:A5000,0)+1)}
1.700859 Seconds Elapsed |
5,301,902 Ticks Elapsed
{=SMALL(A1:A5000,INDEX(FREQUENCY(A1:A5000,0),1)+1)}
1.935807 Seconds Elapsed |
6,034,279 Ticks Elapsed
{=MIN((NOT(A1:A5000)* MAX(A1:A5000))+ A1:A5000)}
3.127774 Seconds Elapsed |
9,749,865 Ticks Elapsed
{=MIN(If(A1:A5000>0,A1:A5000))}
3.287850 Seconds Elapsed |
10,248,852 Ticks Elapsed
{"=MIN(((A1:A5000=0)* MAX(A1:A5000))+ A1:A5000)"}
3.328824 Seconds Elapsed |
10,376,576 Ticks Elapsed
{=MIN(IF(A1:A5000=0,MAX(A1:A5000),A1:A5000))}
3.394730 Seconds Elapsed |
10,582,017 Ticks Elapsed
min() fuction exlude BOOLEAN and STRING values.
if you replace your zeroes with "" (empty string) - min() function will do its job as you like!
In Microsoft 365 you can use the new function MINIFS
=MINIFS(A1:E1;A1:E1;">0")
gives 1
=MINIFS(A1:E1;A1:E1;">1")
gives 18
*replace ; with , if using english version
All you have to do is to delete the "0" in the cells that contain just that and try again. That should work.
Which formulae in MS Excel can we use for -
equi-depth binning
equi-width binning
Here's what I used. The data I was binning was in A2:A2001.
Equi-width:
I calculated the width in a separate cell (U2), using this formula:
=(MAX($A$2:$A$2001) - MIN($A$2:$A$2001) + 0.00000001)/10
10 is the number of bins. The + 0.00000000001 is there because without it, values equal to the maximum were getting put into their own bin.
Then, for the actual binning, I used this:
=ROUNDDOWN(($A2-MIN($A$2:$A$2001))/$U$2, 0)
This function is finding how many bin-widths above the minimum your value is, by dividing (value - minimum) by the bin width. We only care about how many full bin-widths fit into the value, not fractional ones, so we use ROUNDDOWN to chop off all the fractional bin-widths (that is, show 0 decimal places).
Equi-depth
This one is simpler.
=ROUNDDOWN(PERCENTRANK($A$2:$A$2001, $A2)*10, 0)
First, get the percentile rank of the current cell ($A2) out of all the cells being binned ($A$2:$A$2001). This will be a value between 0 and 1, so to convert it into bins, just multiply by the total number of bins you want (I used 10). Then, chop off the decimals the same way as before.
For either of these, if you want your bins to start at 1 rather than 0, just add a +1 to the end of the formula.
Best approach is to use the built-in method:
http://support.microsoft.com/kb/214269
I think the VBA version of the addin (step 3 with most versions) will also give you the code.
Put this formula in B1:
=MAX( ROUNDUP( PERCENTRANK($A$1:$A$8, A1) *4, 0),1)
Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.
General pattern is:
=MAX( ROUNDUP ( PERCENTRANK ([Range], [TestCell]) * [NumberOfBuckets], 0), 1)
You may have to build the matrix to graph.
For the bin bracket you could use =PERCENTILE() for equi-depth and a proportion of the difference =Max(Data) - Min(Data) for equi-width.
You could obtain the frequency with =COUNTIF(). The bin's Mean could be obtained using =SUMPRODUCT((Data>LOWER_BRACKET)*(Data<UPPER_BRACKET)*Data)/frequency
More complex statistics could be reached hacking around with SUMPRODUCT and/or Array formulas (which I do not recommend since are very hard to comprehend for a non-programmer)