Unable to use INDEX COUNT for referencing all of the rows in a Google Sheet - google-sheets-formula

I am trying to use the format/formula A:INDEX(B:B, COUNTA(A:A)) to reference all of the rows until the first empty one and it is not working.
If I skip the first row, then the formula works: A2:INDEX(B2:B, COUNTA(A2:A)).
What am I doing wrong?

I believe because you're using the number of rows to define the end of the data (using INDEX), you have to include a defined starting row. I think this should work for you:
=QUERY(A1:INDEX(B:B, COUNTA(A:A)), "SELECT *")
That is assuming you don't have data that exists beyond the first blank row.

Related

Power Query - conditional replace/clear entire cell in multiple columns

I'm trying to clear the entire cell if it doesn't contain a given keyword.
I've managed to do this for one column:
Table.ReplaceValue(#"PrevStep",each [#"My Column"], each if Text.PositionOf([#"My Column"],"keyword")>-1 then [#"My Column"] else null,Replacer.ReplaceValue,{"My Column"})
The problem is I need to iterate/repeat that step for a number of columns... the number of columns may vary and column names also may be different every time. I can have all those column names put into a list but I'm not able to use it.
The solution I'm looking for may look like this
for each ColNam in MyColumnsList
Table.ReplaceValue(#"PrevStep",each [#"ColNam"], each if Text.PositionOf([#"ColNam"],"keyword")>-1 then [#"ColNam"] else null,Replacer.ReplaceValue,MyColumnsList)
next
but this is not the VBA code but Power Query M - and of course the problem is with #PrevStep as I would see it like a recursions... again... do not know how to process.
Is the path I follow correct or should it be done some other way
Thanks
Andrew
Unpivot your columns to turn all the columns into two columns. Apply your replacement to the single value column then pivot it back into the original format

Insert a new Google Sheets row into Alphabetically Sorted spreadsheet

I am working with two spreadsheets; the first spreadsheet takes a name and then automatically adds it to the next spreadsheet which is sorted alphabetically by name. The problem is, I need a new row to be created, otherwise the data from the row above it gets added along with the name. Here is the query I am using: '=query(Referrals!A2:O, "select * where C is not null order by D")'. I don't think this can be done with a query, so I have been exploring Google App Scripts. I am not sure how to insert into the pre-sorted list, though. Any help is greatly appreciated!
Have you tried offsetting the header so you can run it for the range of the sheet?
=query(Referrals!A:O, "select * where C is not null order by D Offset 1")
That seems to fix some of the issues I've come across.
EDIT:
What about using a filter formula?
=sort(FILTER(offset(Referrals!$A:$O,1,0),offset(Referrals!$C:$C,1,0)<>""),4,true)
If using Apps Script, then you can directly insert a row (via Sheet.insertRows(rowIndex, numRows)) into the sheet at the desired index. But I believe you can achieve what you want by mapping the data in "next spreadsheet" to the names imported via "query" using VLOOKUP. That way when new data is added to "first spreadsheet" it will be sorted accordingly with your formula, but now the data associated will move rows to continue matching their respective row.

How to get the sum of values of a column in tmap?

I have 2 columns - Matches(Integer), Accounts_type(String). And i want to create a third column where i want to get proportions of matches played by different account types. I am new to Talend & am facing issue with this for past 2 days & did a lot of research but to no avail. Please help..
You can do it like this:
You need to read your source data twice (I used tFixedFlowInput_1 and tFixedFlowInput_2 with the same data). The idea is to calculate the total of your matches in tAggregateRow_1, it simply does a sum of all Matches without a group by column, then use that as a lookup.
The tMap then joins your source data with the calculated total. Since the total will always be one record, you don't need any join column. You then simply divide Matches by Total as required.
This is supposing you have unique values in Account_type; if you don't, you need to add another tAggregateRow between your source and tMap_1, in order to get sum of Matches for each Account_type (group by Account_type).

Returning the last value from the FILTER function in google sheets

I'm using Google Sheets and would like to get the last value in column when it is filtered based on the values in a separate column as shown in the screenshot:
I'd like to get the last value from column A, where the value in column B matches that specified in cell D1.
I've managed to do this with the following:
=INDEX(FILTER($A:$A,$B,$B=$D$1),COUNTA(FILTER($A:$A,$B:$B-$D$1)),1)
This works but it seems unnecessary to have the second FILTER and COUNTA as it makes it harder to understand. Is there no way I can just return the last value from the FILTER function?
Since posting this I've found another way that's more concise, but I have to confess I don't actually understand how it works:
=ArrayFormula(LOOKUP(2,1/($B:$B=$D$1),$A:$A))
Here you will know about sort and array_Constrain:
=array_constrain(filter(sort({A1:A,row(A1:A)},2,false),B1:B=D1),1,1)
or you can use query:
=query(filter({A1:A,row(A1:A)},B1:B=D1),"Select Col1 order by Col2 desc limit 1")
or you can use indirect:
=indirect("A" & max(filter(row(A:A),B:B=D1)))
I know this is a way that I do that sometimes. it takes advantage of the VLOOKUP(....TRUE) [default] option.
=VLOOKUP(9^99,FILTER({ROW(A:A),A:A},B:B=D1),2)

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)

Resources