This is for Google Sheets or I could also write a script for it.
I am a teacher and am trying to create a formula or function that will calculate the distance a range of test scores are away from a set number (70 -- a passing grade).
I have my data in a column as a variety of percentages. I would like the formula or function to first check the range for any values that are less than 70. Then, for the values that are less than 70 it would figure out how far each of those values are from 70 and add them all together. Finally, it will take the sum of the added values and divide by the number of values that fit the criteria (less than 70).
Any ideas on how I would accomplish this? Thanks!
There are numerous formulas you can use: sumif, countif, and averageif
But if you want a dashboard-like spreadsheet that gives you quick summaries, filter is very useful.
Here is an examples of using filters
In particular, the formula is =average(arrayformula(filter(B2:B10,B2:B10<70)-70)), where
filter(B2:B10,B2:B10<70) gives you B values that are < 70
filter(…) - 70 finds the difference
arrayformula(…) is needed because you are working with an array
average(arrayformula(…)) finds the average of the array
Related
I was faced to a situation where I have to classify a list of numbers based on the size of the number.
For example, number between 2 and 8 is classified in class A. Number 16 to 25 is classified in class C. I can work on it with IF formula, but it doesnt feel good since it was like brute forcing IF within IF within IF and it is bad.
Is there any ARRAYFORMULA that can help me work on this? An arrayformula that doesnt need to be dragged down when data is added below. Maybe a formula that is related to VLOOKUP or any other formula will do.
This is the sample case:
https://docs.google.com/spreadsheets/d/1Dlrgp-aAlU2DknlG5u5XWJdXDpU5qj6EfofiCO3UTDQ/edit#gid=0
Range A:A is the given data
Range B:B is the desired outcome
Range E:F is hte condition that has to be met
You can do a lookup on the lower end of each range:
=ArrayFormula(if(A:A="","",vlookup(A:A,{split(E1:E9,"-"),F1:F9},3,true)))
assuming there are no values more than 1200.
I'm on google sheets trying to find the percentage of values where the difference between two columns in another sheet, is less than the value in a third column of the sheet. I've tried a bunch of things but all come up with err0rs or parse error. Any help is appreciated.
This is what I came up with.
=COUNTIF((sum(Data!($E$2:$E$229):Data!($F$2:$F$229)),"<Data!$C$2:$C$229"))/count(Data!$C$2:$C$229)
then I make it a percentage value
Thanks for your help!
If possible, the simplest strategy would probably be something like this:
In the sheet with the two columns, calculate another column that is the difference of the first two. E.g.:
=A1-B1.
Then, write an if statement that checks whether that difference is less than the value in the third column. If it is, return 1, if it isn't return 0. E.g.:
=IF(C1<D1, 1, 0)
Finally, calculate the percentage of values that are less with a formula like this:
=SUM(if_column) / COUNTA(if_column) * 100
SUM returns the count of all cells whose difference is less than the third column and COUNTA returns the total number of non-blank cells.
I have my data organised in a NxN table with coupled columns {quantity,code} (see image below).
I'm looking for a function able to calculate total quantity by code.
I've tried with SUMIF, but it seems to work only with a fixed sum range, whilst I need a RELATIVE sum range.
Can you address me to the right solution?
i think this should work:
=ARRAYFORMULA(SUM(A2:G4*(B2:H4=A7)*(A1:G1="quantity")))
just using multiplication of booleans to get at the correct values is sometimes simpler.
I want to use the ARRAYFORMULA version of =IFERROR(AVERAGE(B29:H29),""). This is to calculate a 7 column rolling average that will automatically drag across using the array formula. I am aware the AVERAGE cannot be used with ARRAYFORMULA but I have struggled to find an alternative.
As discussed in the comments you can modify the previous answer.
Another approach to get the running average of the current number and the next 6 numbers is to take the difference of two running sums and divide by the count like this:
=ArrayFormula(if(C1:1="","",
(sumif(column(C1:1),"<"&column(C1:1)+7,C1:1)-sumif(column(C1:1),"<"&column(C1:1),C1:1))/
countifs(column(C1:1),"<"&column(C1:1)+7,column(C1:1),">="&column(C1:1),C1:1,"<>")))
(you can't use AVERAGEIFS or SUMIFS because they don't work with array formulas).
For completeness, the more usual running average starting with the first number, then the average of the first two numbers etc. would be given by:
=ArrayFormula(if(C1:1="","",
(sumif(column(C1:1),"<="&column(C1:1),C1:1)-sumif(column(C1:1),"<="&column(C1:1)-7,C1:1))/
countifs(column(C1:1),"<="&column(C1:1),column(C1:1),">"&column(C1:1)-7,C1:1,"<>")))
I have the following function
=IF(RAND()<0.25,1,0)
RAND() returns any value between 0 to 1 in decimal format and the idea is that an item has a 25% chance of getting a 1. If it was less than 0.25 the rand() then its a hit and gets a 1 otherwise a 0. Now lets say I need to do this 100 times and add up the sum of all the '1's that were created, which in this case will average to around 25 for 25%. How do I do this in Google Spreadsheets?
Basically looking for a way to repeat a function n'th amount of times and sum the results.
I have looked around everywhere (youtube, google forums) and have not found any solutions.
I may as well put this as an answer because it tries to address the broader question of whether you can repeat a function (say) 100 times. The answer is, yes if the function is compatible with an array formula. Rand can't be used in this way because it doesn't take any arguments (neither do some other functions like countifs for some reason). But you could get round it by using Randbetween instead and providing it with 100 array elements. These are multiplied by zero so don't actually affect the answer, but Google Sheets still evaluates the function 100 times:
ArrayFormula(sum(if(randbetween(0,A1:A100*0+99)<25,1,0)))
or
=Sumproduct(if(randbetween(0,A1:A100*0+99)<25,1,0))
The result is each time you force this to re-calculate (by changing something in the range A1:A100 or by setting File -> Spreadsheet Settings -> (Tab) Calculation -> Recalculation to every minute) it will give an answer around 25.
To make it more resilient (allow any value in A1:A100 including error values) could try
=ArrayFormula(sum(if(randbetween(0,iferror(A1:A100/0,0)+99)<25,1,0)))
or
=Sumproduct(if(randbetween(0,iferror(A1:A100/0,0)+99)<25,1,0))
I don't know why I didn't do this in the first place
=ArrayFormula(sum(if(randbetween(0,row(A1:A100)*0+99)<25,1,0)))
then this easily allows for a variable range
=ArrayFormula(sum(if(randbetween(0,row(indirect("A1:A"&H1))*0+99)<25,1,0)))
where the number in H1 doesn't have to be limited to the number of rows in the sheet.
Okay so I found a very convoluted answer. If someone finds a better please let me know.
The first thing as the user |'-'| commented was to create a range on separate sheet.
Since I know that I will not be looking up more than 200 values at once I created my range to be 200 long of this formula.
=IF(RAND()<0.25,1,0)
This will create the initial list of random values.
The next step is you need to generate a randomizer seed. Which is basically a random number between the range you created. You can do this with
=RANDBETWEEN(1,200)
This should be on the same column as what you are trying to sum up later.
Next you want to create a dynamic string that you can access via arrayFormula later.
="Randomizer!B"&B12&":B"&B12+B3
In my case I had the 200 random numbers on a sheet called randomizer. Notice the &, this is how you connect strings. In my example B12 is the reference to the =RANDBETWEEN(1,200), and B3 is how many times I want the randomness to occur. It can be any value as long as it's less than the randomizer seed by the amount of times you want it to be random.
Finally refer to this string using, =SUM(ARRAYFORMULA(INDIRECT(B13))) , indirect lets you refer to a string as a cell and this is how I was able to create a dynamic range to calculate from.
I will say the advantage of this method is its super fast to calculate since the random numbers have been pre-computed.
The idea is that it will keep creating random ranges from the precomputed random numbers you created, and then summing those ranges, essentially calculating random numbers n'th amount of times.
Hope this helps someone.