Google Sheets Row Number of nth Instance from a column in another spreadsheet - google-sheets-formula

I have used the following google sheets formulas to obtain the row number for the nth instance of cell k3 within column A.
=ArrayFormula(SMALL(IF($A$4:$A$20000=K3,ROW($A$4:$A$20000)-MIN(ROW($A$4:$A$20000))+4),n))
I also used the following formula but it only works for the 1st instance.
MATCH(K3,A4:A20000,0)+ROW(A4:A20000)-1
I need to get the row number of the nth instance but for a range in another spreadsheet. I have tried replacing every instance of $A$4:$A$20000 in the 1st formula above with the string below but to no avail. I also tried it without the IMPORTRANGE().
IMPORTRANGE("myurl","mysheetname!$A$4:$A$20000")
Please help me to get that row number. Cheers.

Try:
=filter(row(A4:A2000),A4:A2000=K3,countifs(A4:A2000,A4:A2000,row(A4:A2000),"<="&row(A4:A2000))=K4)
Where cell K3 is what you're looking for and K4 is the instance number (which you can hard code if you want).
Update for your sample sheet:
To bring in the data from another sheet, load it into your final sheet rather than trying to put the importrange() in the formula:
Then the formula in cell A9 can reference the imported range (identifying the row number for the second instance of "BAG1"):
=filter(row(A2:A6),A2:A6="BAG1",countifs(A2:A6,A2:A6,row(A2:A6),"<="&row(A2:A6))=2)

I got this to work...
=VLOOKUP("BAG1"&3,IMPORTRANGE(url,Sheet1!A2:C6),3).
It finds the instance of BAG1 that has 3 in the neighbouring column and then retrieves the value in column 3.

Related

Writing a formula in a cell in Google Sheets that averages the results from a column derived from expected values in multiple columns

I'm an average user of Google sheets and I've tried writing/looking up the formula I'm going for, but I haven't had any luck yet.
I have a spreadsheet that details multiple values that I need to display in a single cell the average of a certain set of values derived from a specific set of those values from multiple columns.
The flow of information would look something along the lines of:
if value in Column D=L
then
if value in Column J<$1.20
then
Find Avg of all Values in Column N
I'd need the formula to narrow it's field of data each time so the final result was the average of all the values in Column N that had a value in column J<$1.20 with a value in Column D=L.
I feel like a dummy over here because I just can't narrow down how I should write this flow and get it to work right without adding multiple extra hidden columns. Can anyone help on this one?
I've tried writing the formula multiple different ways but haven't kept it written down to pass on.

Google Sheets - COUNT UNIQUE values by group ONLY IF NOT already counted in previous group

I hope to explain clearly what I'm trying to do.
I have some data in column B, grouped as shown in column A.
I'd like to count the unique values for each group present in column A, not taking into account the unique values already counted in the previous group(s).
For instance, I'd like to:
count unique values in 'proyecto2' NOT COUNTING the unique values already present in 'proyecto1'.
count unique values in 'proyecto3' NOT COUNTING the unique values already present in 'proyecto1' and 'proyecto2'.
count unique values in 'proyecto4' NOT COUNTING the unique values already present in 'proyecto1', 'proyecto2' and 'proyecto3'.
and so on...
Below you can find a Google Sheet with the solution I found, even if I'm not very happy with it, to show easily what I mean.
https://docs.google.com/spreadsheets/d/1x8S76_6dUnHr1NtUbzNzpLTpQtqan6_ohemcrGsrpC0/edit#gid=0
Basically, in column A:B, we have the INPUT DATA. You can add data in column A and B to see how it works (my method, at the moment, only work if you add one of these groups in column A: 'proyecto1', 'proyecto2', 'proyecto3', 'proyecto4', 'proyecto5' and 'proyecto6').
In column D:E, we have the output data, basically, the unique values counted by the group.
In column G:W, the formula to process the data.
Clearly, my method is working up to 'proyecto6' since in the "processing columns" I'm taking into account formula only up to 'proyecto6'.
Everything is working but my question is: could you suggest me a more dynamic way of achieving what I'm trying to do? Or the only way is to write some code?
delete everything in range D:Z
paste to D2 cell:
=UNIQUE(A2:A)
paste to E2 cell:
=ARRAYFORMULA(IF(LEN(D2:D);
MMULT(IFERROR(LEN(G2:Z)/LEN(G2:Z); 0); TRANSPOSE(COLUMN(G2:Z2)^0)); ))
paste to G2 cell:
=TRANSPOSE(UNIQUE(FILTER(B$2:B; A$2:A=D2)))
paste to G3 cell and drag down:
=TRANSPOSE(UNIQUE(FILTER(FILTER(B$2:B; A$2:A=D3);
NOT(COUNTIF(INDIRECT("G2:"&ROW()-1); FILTER(B$2:B; A$2:A=D3))))))

Excel 2017 Formula - Average data by month, while being filterable

I'm not a VBA coder, and I would prefer an excel formula if possible, the easiest solution will be the best one.
Test workbook screenshot
As you can see, I have plenty of columns, which are filterable.
I am attempting to retrieve an average of Column L, but I want the data to be calculated for the correct month in G3:R3.
The resulting calculation needs to be recalculated when filtered, between customers, sites, status, job type etc.
I am referencing the resulting cells in another sheet, which gives an idea of trends I can glance at, as such filtering by month in each sheet, is not an option.
=AVERAGE(IF(MONTH(E9:E1833)=1,(J9:J1833)))
This one does not update with the filtered data.
=SUM(IF(MONTH(E9:E1833)=1,J9:J1833,0)) /SUM(IF(MONTH(E9:E1833)=1,1))
This one does not update with the filtered data.
I have tried 5 different SUBTOTAL formulas, some with OFFSET, none of these produce the same result I get when checking manually.
Each worksheet has over 1,500 hundred rows, the largest is 29148 rows. The data goes back as far as 2005.
Please can someone help me find a solution?
One possible solution is to create a helper column which returns 1 if the row is visible and returns 0 if the row is invisible (or blank). This allows a bit more freedom in your formulas.
For example, if you want to create a helper column in column X, type this into cell X9 and drag down:
= SUBTOTAL(103,A9)
Now you can create a custom average formula, for example:
= SUMPRODUCT((MONTH(E9:E1833)=1)*(X9:X1833)*(J9:J1833))/
SUMPRODUCT((MONTH(E9:E1833)=1)*(X9:X1833))
Not exactly pretty but it gets the job done. (Note this is an array formula, so you must press Ctrl+Shift+Enter on your keyboard instead of just Enter after typing this formula.)
With even more helper columns you could avoid SUMPRODUCT altogether and just accomplish this by doing a single AVERAGEIFS.
For example if you type into cell Y9 and drag down:
= MONTH(E9)
Then your formula could be:
= AVERAGEIFS(J9:J1833,X9:X1833,1,Y9:Y1833,1)
There isn't a clean way to do this without at least one helper function (if you want to avoid VBA).

Is it possible to get the last row filled?

In gspread, is it possible to get the last row or cell number that is filled?
The API reference page doesn't seem to help.
Gspread has "row_count", but I am not sure it returns all rows in a spreadsheet, or just the filled ones. If that doesn't help, there is a slightly less direct, but completely functional way to do it:
1.) let's assume your data is in column A, and it has been filled in consecutively row by row (i.e. no skipped rows)
2.) in another free cell in your spreadsheet--let's assume cell B1--use the native Google Sheets function COUNTA, which will count the number of values in a dataset, and specify column A as the target, i.e. "=COUNTA(A:A)"
3.) now just request the value of cell B1 with gspread's acell, i.e. "last_row_updated = myWorksheet.acell("B1").value"
You can use the following code, taken from this answer to this similar question:
def last_filled_row(worksheet):
str_list = list(filter(None, worksheet.col_values(1)))
return len(str_list)

sorting in excel error when duplicate data

I am trying formula for sorting of a column in excel. Data is entered in one column and sorted data is output in another one. Please see attached excel file.
As you can see due to same data in second column I am getting rank 2 twice and VLOOKUP cannot find entry named 3 so it is giving error. When all data entered are unique there is no problem but in case of duplicated data I am having problem. What can I do?
Kbv.
Just noticed a third possibility that you miight be looking for. So you want to sort the B items where column A indicates the rank of each item in B:
C2
=VLOOKUP(SMALL($A$2:$A$7,ROW(1:1)), $A$2:$B$7, 2,FALSE)
Old answer:
If you want a custom sort where column A indicates the rank of the resulting item inC , copy the following formula in C2 and fill down.
C2
=SMALL(B$2:B$7,A2)
If you want just to copy the column as sorted "naturally", you dont need any helper column, just type this in the first row and fill down (I used column D in my example image below):
D2:
=SMALL(B$2:B$7,ROW(1:1))

Resources