Google sheets percentage of values where the difference between two columns in another sheet, is less than the value in a third column of the sheet - google-sheets

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.

Related

Google Sheets array formula not working for negative numbers

I have used this formula so many times and cannot get it to work for values less than zero
Formula: =ArrayFormula(iferror(index(PayrollSummary!A:A,small(if(PayrollSummary!I:I<0,row(PayrollSummary!I:I)),row(4:4))),""))
I use this to find the text of one column based on the value of another. It is the if(PayrollSummary!I:I<0 that is not working, if I change it to less than 1 I get values from 0-1, but not the ones less than 0.
I have checked the formatting on the column, tried number, financial, custom number formats. I have put the PayrollSummary!I:I within VALUE() I have tried LTE(), it will not give be the negative numbers.
try:
=ARRAYFORMULA(IFERROR(INDEX(PayrollSummary!A:A, SMALL(
IF(PayrollSummary!I:I*1<0, ROW(PayrollSummary!I:I)), ROW(4:4))), ))

Google Sheets vectorized operations

I have a Google sheet with a column of dates and numbers. What I want to be able to do is say: If the date is earlier than 9/1/2021, take the number and multiply by 1, otherwise multiply by 2, then sum all the products. The date and number columns keep getting new information as time goes on.
Now I know that I could create a kind of "scratch-work" column where I have a cell containing =IF(DATEVALUE(A1)<DATEVALUE("2021-9-1"),1,2) * B1 and then apply this formula to the column, and then sum the column somewhere else. However, this is not ideal because every time a new date and number come in I have to reapply the formula to the new scratch-work column's cell.
What I was hoping for was some kind of vectorized operator that would eliminate the need for the scratch work column in the first place. Something like being able to multiply whole columns like =B1:B * 2 or what is more appropriate for my current task, =IF(DATEVALUE(A1:A)<DATEVALUE("2021-9-1"),1,2) * B1:B.
I know you can do this kind of thing in R but haven't seen any vectorized operations in Google Sheets. I'm guessing it's not possible but wanted to ask just in case.
=arrayformula(if(A1:A="","",IF(DATEVALUE(A1:A)<DATEVALUE("2021-9-1"),1,2) * B1:B))

Excel/Sheets Consecutive Count Based on Two Conditions (function?)

I have a Google Sheet, and I'm trying to see if it's possible to get a consecutive count outputted in a third column based on the values of two other columns.
My columns are:
Column A: Will have a handful of text values that are "grouped" together. Likely around 30 of the same value, until it changes to another value. In the image above, these are text1, and text2.
Column B: Will have one of 3 values assigned to each value in column A. In the image above, these are id1, id2, id3.
Column C: Will output a consecutive count based on the values of the first two columns. My hope is that if there are multiple ID1,ID2 in consecutive order, they'll repeat that first +1 value; while ID3 is always plus 1 to the count. This is what I am trying to show in column C in the layout image above.
I've hit a wall with trying to accomplish this with various COUNTIF iterations.
Thanks for any help, or any better ideas to accomplish something similar.
(I'm hoping for a formula, but open to being pointed into a direction for a script if that's the only way).
You can try following formula:
=IF(A2=A1;IF(OR(B2="id3";B2<>B1);C1+1;C1);1)
It is also possible to do this as an array formula. I used offset ranges for column B in the first Countifs to check for a change in value but this made it a little awkward to get equal-sized arrays:
=ArrayFormula(if(A2:A="","",
countifs({"";B2:B}<>{B2:B;""},true,{A2:A;""},A2:A,row(A:A),"<"&row(A2:A),{B2:B;""},"<>id3")+
countifs(A2:A,A2:A,row(A2:A),"<="&row(A2:A),B2:B,"=id3")
))

How to make a column of repeated text in Google Sheets?

I'm using this Google-sheets formula for a spreadsheet:
=ArrayFormula(IF(ROW(A1:A1000)+TRUE;"Sometext to show";""))
To fill 1000 columns with the same text, but I think there must be a formula or something more efficient to do so.
=ARRAYFORMULA(IF(IF(1:10000, )=FALSE, "SPAM"))
The solution really depends on why you want the same information replicated across multiple rows. Does that data ever need to change? If not you possibly don't need the column at all.
Strictly in terms of efficiency it would be better to copy-paste set values into those 1000 rows rather than using a formula, since the formula will need to be evaluated every time the sheet loads.
If you need a dynamic length of repetitions and a dynamic version of text then modify your formula slightly:
=arrayformula(if(row(A:A) <= 1000,"this row is 1000 or less","this row is over 1000"))
This checks all of column A and if the row number is 1000 or less it populates that field with the given text otherwise it fills the row with the alternative text

Google Docs - SUMIF - SUM range if single cell contains a string

I'd like to quickly include or exclude an entire range of values in a SUM.
Presently I'm SUMing select cells for a grand total: [E19] =SUM(E13,E20,E30,E45,E55,E70,E80)
These are in turn SUMs of selected ranges:
... [E30] =SUM(E31:E44), [E55] =SUM(E56:E69), ...etc.
One of these ranges I would like to toggle it's inclusion in the Grand Total.
It seemed the best way to do it was this:
[E45] =SUMIF(D45,"☑",E46:E54)
In short, in cell E45 I'd like to SUM E46 to E54 only if D45 contains a ☑.
However Google Doc's SUMIF seems to only work with matched ranges: =SUMIF(D46:D54,"☑",E46:E54)
Is there a way to SUM a range only if a specific value exists in a single cell?
You're right about SUMIF, it allows you to sum values from a range, which meet a certain criteria (on another range of the same length). For example, if you had two columns called "status" and "price", you could use it to sum all the prices for a given status.
What you're trying to do can be done, instead, with the use of the IF function:
=IF(D45="☑";SUM(E46:E54);0)
If the condition specified in the first argument is true, it will return the second argument, that is, the sum. Otherwise, it will return the third argument, 0.
After working through the logic to share the issue I wound up identifying a solution. Rather than trying to force SUMIF to check a single cell against a range. I just nested the 1:1 SUMIF inside my 'Grand SUM': =SUM(E13,E20,E30,SUMIF(D45,"☑",E45),E55,E70,E80).

Resources