Count results across multiple conditions in Excel - excel

I have the following table in which I want to compare scores across simulations for multiple players. How can I get the number of times that Phil Mickelson has a lower R1Score than Justin Rose?
This needs to be done in a formula of sorts, not using any PivotTables. I would need to compare the R1Score for Phil and Justin for SimNum 1, 2, 3, etc. to see how many times he beats Justin. Any help would be greatly appreciated!

If you have Office 365 you could use:
=SUM(IFERROR(--(FILTER(C2:C21,A2:A21="Phil Mickelson")>FILTER(C2:C21,A2:A21="Justin Rose")),0))
This is provided that the SimNum are in ascending order always.
If they're not in order but all values from 1 to x are present without any gaps, you could use the following:
=LET(value1,"Phil Mickelson",
value2,"Justin Rose",
data,A2:C21,
sorted,SORTBY(data,INDEX(data,,2)),
a,INDEX(sorted,,1),
c,INDEX(sorted,,3),
filter1,FILTER(c,a=value1),
filter2,FILTER(c,a=value2),
SUM(IFERROR(--(filter1>filter2),0)))

If your version of Excel has dynamic arrays this is easy to solve.
Start with this formula:
=COUNTIFS($C$12:$C$21,">"&C2)
If we drag that down column D we get these numbers: 9, 8, 9, 6, 4, 4, 9, 0, 8, 2 i.e. Simulation 1 is better than 9 simulations of Justin Rose, simulation 2 is better than 8, simulation 10 is better than 2 etc.
With Dynamic Arrays, instead of just supplying the cell containing Phil's first simulation, we can now provide his entire simulation range as well. This will give us a dynamic array, containing the same numbers as our original COUNTIF formula. Take note that the range is surrounded by a blue border.
Now we just need to add all of these numbers together to show how many total simulations are better:
=SUM(COUNTIFS($C$12:$C$21,">"&C2:C11))

Related

Why is Excel not calculating the cube root as the cube root?

I have a suspicion Excel is calculating exponents that are repeating decimals represented as a fraction (e.g. 1/3) differently than ones that don't have repeating decimals (e.g. 1/2). It is preventing me for a formula that finds perfect cubes in a list of numbers.
Column A lists numbers 1 to 100.
Column B has the following formula (starting with row 5):
=IF($A5^(1/2)-ROUND($A5^(1/2),0)=0,1,0)
This should return "1" if the number in column A is a perfect square, like 1, 4, 9, etc. and does so correctly. This other formula I originally wrote also works: =IF(SQRT($A8)-ROUND(SQRT($A8),0)=0,1,0).
Column C has the following formula (starting with row 5):
=IF($A5^(1/3)-ROUND($A5^(1/3),0)=0,1,0)
Note that it is the exact same as the perfect square identifying formula, except there is a 3 where there was a 2. This is not returning a "1" for perfect cubes like 8, 27, 64. etc. (but does return a "1" for the number 1).
Can anyone help me correct this?
I apologize for not knowing how to pick a comment as an answer, so I aggregated the helpful comments and am posting them as an answer.
Main Explanation:
See Floating-point arithmetic may give inaccurate results in Excel. If you examine the underlying xml, you will see that Excel is calculating A1^(1/3) as 1.9999999999999998. The article explains why, and suggests some work arounds. – Ron Rosenfeld
Workaround I picked:
Can't you replace $A5^(1/3)-ROUND($A5^(1/3) with $A5 - ROUND($A5^(1/3))^3? – r3mainer
Thanks all!

How to find the lowest sum of numbers for corresponding elements equal to given value?

I've the following input
c1, c2
1, 41
2, 76
3, 109
4, 133
5, 149
6, 157
7, 174
8, 185
9, 200
10, 211
11, 223
12, 232
13, 245
14, 258
What I need to do is to find the lowest sum of c2 for which sum of corresponding values from c1 is equal to 24. E.g. for 10 and 14 sum is 469. I suppose that this is something simple for an experienced excel user which I'm definitely not. Values can be used more than once so 3*8 works well as well as 3*7+3.
It seems like quite of a hard question. I think it's actually a fundamental issue of computer science you are trying to tackle. You can have a look on the Knapsack problem on wiki for further theoretical discussion, so I don't believe you are going to get both simple and totally correct answers. (https://en.wikipedia.org/wiki/Knapsack_problem)
Anyhow, if the values of c1 are simple enough, lets say integers (no fractions or real numbers) you can use dynamic programming technique, meaning solving many sub-problems similar to your question but for sum lower then 24 and for less rows then what you have. Combining these together can help you solve the harder question.
Lets define SubProb(N,i) = the solution for sum N in c1, using only 1...i rows.
If so, SubProb(N,i) = min(taking an instance from the i-th row, not taking any instance on the i-th row). Theses are all the options available.
in that case it's the minimum of two simpler problems:
Taking an instance from the i-th row meaning you now need to take only N-i more from c1 and can still use only 1...i rows, so it is the SubProb(N-i,i), + c2 value of i.
Not taking any instance on the i-th row meaning you can just take the result of SubProb(N,i-1).
Now we calculate all these problem up to SubProb(24,14) in a clever order and get the answer we wish. The simplest way of doing this is to put them in a table with axis N,i so it is easy to pull values without many recursive overhead.
I implemented this for you in an excel file, here is the link. If you wish to do it on bigger i or N just extend the table by dragging the last row and column of it with the extension tool (the tiny black cross in the corner of the cell). It can be found on this link:
https://drive.google.com/open?id=1K0iROL9mb2NURM7Q0oUKzAFH4jNxNGtk
Oh, and the answer is 464.

Excel: Dividing numbers and using the remainders

Little issue I'm having that I'm hoping someone can help me with please?
So I have 3 columns in Excel. Each Column (A/B/C) contains either "high" / "Medium" / "Low" scored issues. However, if you have 3 Low issues, this is grouped together, and this becomes 1 Medium Issue for example.
The difficulty I'm having is writing a formula that will do this for me. Obviously I could just divide the number of Low issues I have by 3, but in the case where I have 7 Low issues, It should result with 2 Mediums and 1 remaining Low. I've tried using the "Mod" function, but that only returns the remainder.
What I need is a formula that will say "If you have 7 Low Issues, (3 low = 1 medium), therefore you have 2 medium and 1 Low). The medium issues would then be added to the Medium Column (Col B), and the remaining low issue is counted in the Low issue column (Col C).
I hope this explanation makes sense, fingers crossed one of you might be able to help me! Thank you in advance
As requested, a screenshot!
If I understand you correctly, I think you should be able to adapt the following formulas to meet your needs.
To get the number of occurrences of the word "Low" in column A:
=COUNTIF(A:A, "=Low")
To get the number of "Mediums" from 3 occurrences of "Low" in column A, round down the above number divided by 3:
=FLOOR(COUNTIF(A:A, "=Low")/3,1)
To get the remaining "Lows" after groupings of 3 into "Mediums", use MOD:
=MOD(COUNTIF(A:A, "=Low"),3)
Putting this into a worksheet:
Values
Formulas
Finally, if you wanted one "Mediums" count, i.e. adding the remaining "Mediums" which aren't grouped into "Highs", you would use a combination of the above formulas for what is left after grouping to "Highs" with what is gained from grouping of "Lows".
Edit:
Now you've included an image, I can show how these formulas are directly applicable...
Values
Formulas
Sounds like you were already nearly there with using =MOD() just needed a little tweak:
For the high column:
=COUNTA(A2:A8)+FLOOR(COUNTA(B2:B8)/3,1)
For the medium column:
=FLOOR(COUNTA(C2:C8)/3,1)+MOD(COUNTA(B2:B8),3)
For the low column:
=MOD(COUNTA(C2:C8),3)
It's exactly like a long addition that you do at school where each column carries over to the one to the left of it (except base 3 instead of base 10). I'm not clear that existing answers cover the case where there is a carry from one column and that causes a further carry from the next column so here is another answer
In the totals row (e.g. for the medium column) in (say) C12
=COUNTA(C2:C10)+INT(D12/3)
Then use mod as before
=MOD(C12,3)
except that in the high column you don't want to use MOD so it's just
=B12

In EXCEL, how to get all combinations of numbers that where the sums fall within a certain range?

Hi I am new here and was hope one of you geniuses can help me.
Note, this topic is similar to some out there, but none have answered this exact question.
As an excel user I have a column of numbers, say
5, 6, 7, 8, 8, 9, 14, 17
and what to know all the combinations of sums that fall, for example, within the 25 - 35 range.
There is one more restriction: I want the combinations to be as small as possible, but still within the range.
so 17 + 9 = 26 is good
but 17 + 9 + 5 = 31 is bad (should not be counted) because the group is larger than necessary although it still is within the range.
So overall, I want to get all the possible combinations of numbers in a column that sum to fall within a specific range where the sums are as small as possible, but still within the range.
Hope anyone can help! VBA solutions are welcome - I suspect this is the only way to go.
CHeers and have a wonderful weekend!!
Did you try to use SumIf(S) and give the criteria you want. it will sum you only numbers within the given range. If I understand your question well

How to predict number sequences i.e. Excel?

In Excel, there is a nice feature where if you enter 1, 2, 3 in three consecutive cells and then select the cells and drag down, it automatically fills in the rest of the cells as 4, 5, 6, 7, etc. It is also able to match more patterns. For example, if I did 2, 4, 6, 8, it would recognize I am adding 2 and then suggest 10, 12, 14, etc.
How does Excel know which numbers? Do they hardcode the different cases (i.e. adding some constant, subtracting some constant, multiplying by some constant) or is there some algorithm that can automatically predict this for you? (This question should be language-agnostic, but if it helps, I want to do this in jQuery)
Thanks!
I'm pretty sure it's a simple thing to do. Excel probably checks, when a user enters three numbers, the delta between each consecutive number. If they are the same both times, it will use that delta to predict the next number.
If you want to do this more generically than Excel does (only addition or subtraction of constant values), have a look at some interpolation algorithms from numerical methods point of view. This wikibook article is an ok tutorial.
In Excel, it only works with additions and substractions (that I know of, I just tried with multiplications and the results don't follow the same pattern as the originals).
Knowing that, I think it would be easy to calculate the difference between the first two cell, then check the difference between cell 2 and cell 3 to see if it's the same. You can then apply that transformation to the cells you want to predict.
*Example*
Cell1: 2
Cell2: 5
Cell3: 8
if(cell2 - cell1 == cell3 - cell2)
cell4 = cell3 + (cell2-cell1); //Cell4 will now be 11 since it increments by steps of 3
You could then use a for loop that would copy the value you want to all selected cells (if you want to make the next ten cells follow the pattern, use a for or a while loop that will update the value of those 10 cells)

Resources