Return last n entries from a column - google-sheets-formula

I was wondering how to return the last n entries from a column in Google Sheets.
I have seen how to return the last entry, but say I wanted to return the last 5 entries. What formula is best to use?

You can return the last n entries with the following logic :
=query(Query_formula,"Select * offset "&countif_formula)
You also need to know what your count_formula is. To filter the last n rows you can use this formula :
=countif(B2:B,E2)
This is an example based of the following link's use case :
Filter rows in Google Sheet

Related

List non-unique entries and their counts sorted in descending order

If I have a list of names in a sheet for example:
First Name|Last Name|Something else|
Maria|Miller|...|
John|Doe|...|
Maria|Smith|...|
Marc|Meier|...|
Marc|Park|...|
Maria|Muster|...|
Selene|Mills|...|
Adam|Broker|...|
And then I want a second sheet which then shows the list of non-unique first names and their count, and the list being in descending order. So in this example that would be:
First Name|Count
Maria|3
Marc|2
What I found was this example https://infoinspired.com/google-docs/spreadsheet/sort-by-number-of-occurrences-in-google-sheets/
which sorts of partitions the sheet entries by occurrence.
So as of now I have
=UNIQUE(sort(
Names!C3:Names!C12000;
if(len(Names!C3:Names!C12000);countif(Names!C3:Names!C12000;Names!C3:Names!C12000););
0;
2;
1
))
In the first column and
=IF(ISBLANK(A2);;COUNTIF(Names!C3:Names!C12000; A2))
In the second. This does the job somewhat (it still shows the names with count 1), but the second column needs a copying of each cell downwards for each new entry leftwards. Is there a way to tie this up directly in one line? While filtering out the unique occurrences at that.
(Also the formulas are quite slow. The names sheet has about 11k entries so far. These formulas make the sheet crash at times atm. So I kind of want to sorts of comment out the formulas most of the time and only display them by commenting out the formulas. So the second column also just being one formula would be very helpful.)
use:
=QUERY(SORT(QUERY(A2:A, "select A,count(A) group by A"), 2, ), "where Col2>1", )
I think this should work if your headers are in row 1.
=QUERY(QUERY(Sheet1!A:A,"select Col1,COUNT(Col1) where Col1<>'' group by Col1",1),"where Col2>1 label Col2'Count'",1)

Google Sheets - Find and match value with filter

I have try using query, vlookup and filter to get data from other tab sheets
I don't know how to get data with logic condition.
Here my sheets :
https://docs.google.com/spreadsheets/d/1sukCRlU1UuXS6IaR8xCYs8QScH4B2m60bqsrypDkzTM/edit?usp=sharing
Step 1 :
I have tab sheet with list of reward
Step 2 :
in the other tab sheet (cust_point), in column C i want to get value from tab sheet Reward where it use match and logic condition >= and <=.
Then here my expectation :
Problem :
First, i try with formula
=QUERY(Reward!A2:B, "SELECT A WHERE B <= '"&C2&"'", 1)
then the result just showed but doesn't match
Second, i try with formula
=FILTER(Reward!A2:B,C2>=Reward!B2:B)
Third, i try with formula
=IF(VLOOKUP(C2,Reward!B2:B,1,FALSE), C2>=Reward!B2:B)
They all formula doesn't get value with match data like my expectation
How can I achieve that?
use:
=ARRAYFORMULA(IFNA(VLOOKUP(10000-B2:B;
SORT({10000-Reward!B2:B\Reward!A2:A}); 2; 1)))

Get newest date in Sheet

i have a sheet with two tabs. In the first tab, i can select a site and i have a list of types. I have a second tab with many datas from each type (date, year, month week, and site attached to a type).
I would like in the first tab write a formula to automatically get the newest date of the type depending to the selected site.
I'm not good with formulas but i tried to write one, this one =IF((AND(C1=DATA!F:F),(B3=DATA!E:E)),LARGE(DATA!A:A),"") but i don't have result.
Anyone can help me with my problem please ? This is the link of my Sheet.
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B3); 1; FALSE);1)
=INDEX(SORT(FILTER( DATA!A:A; DATA!F:F = $C$1; DATA!E:E = $B4); 1; FALSE);1)
INDEX(array, [row])
Index gets the nth value in an array, when you pass in the value 1, it will get the top most value.
I created a sorted array by using the FILTER function. and the SORT function. I sorted it descending and only returned the dates in the FILTER function.

Formula for searching a range and returning column headers

I've been working on, or at least trying to develop, a formula that goes through an array of cells, finds the max value and returns a cell that has the month that max value was found in.
Link to Google Sheet
The array I'm trying to search through is B14:M21. Once the max value is found in a column, I'd like to return a value from B13:M13. This return value (the month column where the value was found) is going to be displayed in cell H4.
This same concept would also need to be applied to finding the year the max value is found, just in terms of rows instead of columns. I've tried doing hlookup, vlookup, query, index/match, etc. and none of it has worked for this application.
try:
=FLATTEN(SPLIT(INDEX(SORT(SPLIT(
FLATTEN(B13:M13&"♦"&A14:A21&"♠"&B14:M21), "♠"), 2, 0), 1, 1), "♦"))

Simpler alternative to simultaneously Sort and Filter by column in Google Spreadsheets

I have a spreadsheet (here's a copy) with the following (headered) columns:
A: Indices for a list of groceries;
B: Names for the groceries to be indexed by column A;
C: Check column with "x" for inactive items in column B, empty otherwise;
D: Sorting indices that I want to apply to column B;
Currently, I am getting the sorted AND filtered result with this formula:
=SORT(FILTER(B2:B; C2:C = ""); FILTER(D2:D; C2:C = ""); TRUE)
The problem is that I need to apply the filter two times: one for the items and one for the indices, otherwise I get a mismatch between elements for the Sort function.
I feel that this doesn't scale well since it creates duplication.
Is there a way to get the same results with a simpler formula or another arrangement of columns?
=SORT(FILTER({Itens!B2:B\Itens!G2:G}; Itens!D2:D=""))
=SORT(FILTER({Itens!B2:B\Itens!G2:G}; Itens!D2:D="");2;1)
or maybe: =SORT(FILTER(Itens!B2:B; Itens!D2:D="");2;1)

Resources