How to get last item from array (reverse array) Google Spreadsheets - google-sheets

I am using the FILTER formula to get filtered data
=FILTER(A:H,REGEXMATCH(D:D,"......"))
This function returns multiple results from top to bottom of my document.
I need to get the last result from filter function.
How can I achieve this?
I have already tried to transpose, reverse array, etc. But didn't get desired result.
I would be grateful for any help with this matter.

In addition to the contribution of ttarchala, maybe this will also work
=INDEX(A:H,MATCH(2,IF(regexmatch(D:D, "..."),1),1))

=index(
filter(<your_range>, <your_condition>),
rows(filter(<your_range>, <your_condition>))
)
The disadvantage is that you have to repeat the filter parameters twice, maybe someone can improve on this answer?

Related

Unpivoting using QUERY function is not fetching the expected result

I am currently working on a dataset that includes several columns, mostly the dates. What I am trying to achieve is - unpivot all the date columns to use for my subsequent calculations. I use the following formula to unpivot: =ARRAYFORMULA(SPLIT(FLATTEN(Data!A2:A&"|"&Data!D1:AG1&"|"&Data!D2:AG),"|"))
Even though this returns the expected result, when I try to nest this within a Query function, it does not work correctly. This is how I applied the formula - QUERY(ARRAYFORMULA(SPLIT(FLATTEN(Data!A2:A&"|"&Data!D1:AG1&"|"&Data!D2:AG),"|")),"Select * WHERE Col3 IS NOT NULL")
PS: When I change the data range to say, A2:A100, it gives me the correct result. However, it does not help since lot of new data would get added and I want the formula to be dynamic.
Here's the link to the sample sheet - https://docs.google.com/spreadsheets/d/1dgFY5mT9nUJtFefjAros-XpWXRMFtxEf8Fqrv82N5Ys/edit#gid=1813140523
Any help/suggestions would be highly appreciated
Not sure where you got your SPLIT(FLATTEN technique,
but you have to include both the 3rd and 4th parameters of the split function as FALSE or 0. so in your case it would be:
=ARRAYFORMULA(SPLIT(FLATTEN(Data!A2:A&"|"&Data!D1:AG1&"|"&Data!D2:AG),"|",0,0))
If you do that you'll find your query works.
Also note that the way you have it it's not really working. If you look all the way down in column 1 you'll find a bunch of dates formatted to look like integers.

Use Query formula returning a list of results in one cell then split into original form

This question is different with previous one.
Because my function is within query results, the previous answer won't work with a range of data from Query outputs.
I would like to use Query formula returning a list of results in one cell.
Then I want to split Value G6 into original form. Thank you so much.
I knew how to use =JOIN(), =CONCATENATE() function to generate same results. Since my data is huge, I prefer to use Query function to keep my data flexible. Thank you for helping.
https://docs.google.com/spreadsheets/d/1SBw4CME18KNtlopHi4lBtqKuGEueH8EEiVsAy34h6BU/edit?usp=sharing
try:
=ARRAYFORMULA(TRIM(REGEXREPLACE(QUERY(REGEXREPLACE(FLATTEN(QUERY(TRANSPOSE(
IF(QUERY(A1:C3,"SELECT *")="",,
QUERY(A1:C3,"SELECT *")&" |")),,9^9)),
"( \|)$", "×"),,9^9), "× |×$", CHAR(10))))

How to display the values in another sheet in descending order using v look up

Please help me to find a solution which am trying to sort out. my query is i want to display the values in another sheet using v lookup formula in descending order.
I may have an answer that works for you.
Look at Sheet1-GK in your sample worksheet.
The formula I used is:
=vlookup(B2, filter('Price History'!A$2:B$18,'Price History'!A$2:A$18=B2),2,1)
Let me know if you need more. I haven't tried to see if this can be made into an arrayformula, so it doesn't need to be copied down.

Is there a way to prevent duplicates in an array with stacked queries in Google Sheets?

I'm trying to create a simple sort feature in Google Sheets by having data validation drop-down lists and using an array of queries. I can get it to work but if a row matches more than one of the data validation drop down lists, then it will appear twice in the array.
I have tried using vlookup instead but don't really understand how that works as I can only find very specific examples. I have tried using "=ARRRAYFORMULA" and putting my queries inside there but that does not solve the issue either.
My cell currently is
={ IF(NOT(ISBLANK(B2)),
QUERY('App Data Sheet'!1:1006, " select * where B = '"&B2&"'", 0), "");
IF(NOT(ISBLANK(C2)),
QUERY('App Data Sheet'!1:1006, " select * where C = '"&C2&"'", 0), "")
}
where B2 and C2 are data validation cells in the active sheet.
You can view my Query Sheet here: https://docs.google.com/spreadsheets/d/1AgvDIjmn2tv9_zKj7o5MPYZ9CdX9mZ_tM66n5jp5NEY/edit?usp=sharing
I currently only have two drop-down lists but will want to add more later once I figure out the duplicates issue.
EDIT:
I know that you can use countif to see if there are duplicates in a range but I do not how to enter that into my code to prevent it from showing.
EDIT2:
Well, I figured it out. I simply needed to encapsulate my formula inside a =UNIQUE() function that I had not known about before. Hopefully, this post will still help someone else out.
Well, I figured it out. I simply needed to encapsulate my formula inside a =UNIQUE() function that I had not known about before. Hopefully, this post will still help someone else out.
Googling using the proper words is what made a big difference in finding a solution. Instead of saying that I wanted to prevent duplicates, I searched to only show unique rows.

Google Sheets COUNT/FILTER function

I'm having some trouble getting these functions to work. I'm not even sure if they're the ones that I should be using, but here is the following information I can provide. I had previously opened a topic, but I was getting responses about my confusing query. So, hopefully this one is better explained.
I have data in the following fields: A1:N7, as well as A12:L18.
I need a function to check all of the fields and add up the amount of times certain numbers show up. The numbers that need to be checked are: <90, 90-99.99, 100-109.99, and =>100.
First off, I can use this formula to count the <90 and =>100 values in all the fields, which works.
=COUNTIFS(A1:N7,"<90")
However, I'm unsure how to appropriately add the results from A12:L18 into it. My attempts have failed. Likewise, for the ranged functions, I'm completely lost. I've tried something like this:
=COUNT(FILTER(A1:N7,A1:N7>=90,A1:N7<=99.99))
Yet, this always returns 0 as the result. In addition, like the above formula I don't know how I'd nest in a way to check the additional fields in A12:L18.
An old thread, but I came across it trying to solve a similar problem.
Using the original example:
=COUNT(FILTER(A1:N7,A1:N7>=90,A1:N7<=99.99))
I was also getting zero until I realised COUNT returns the number of NUMERIC values in the range. Assuming the result range isn't numeric, I tried:
=COUNTA(FILTER(A1:N7,A1:N7>=90,A1:N7<=99.99))
and got the result I was expecting.
You just need count rows your matrix with ROWS()
=ROWS(FILTER(...))
Does this formula work as you want:
={"<90",COUNTIF({A1:N7;A12:N18},"<90");"90-99.99",COUNTIFS({A1:N7;A12:N18},">=90",{A1:N7;A12:N18},"<100");"100-109.99",COUNTIFS({A1:N7;A12:N18},">=100",{A1:N7;A12:N18},"<110");"=>110",COUNTIF({A1:N7;A12:N18},">=110")}
I made an example sheet where you can see it working: https://docs.google.com/spreadsheets/d/1BPexh5syksapZ9rd_brAa3NkN28LXAvB6dVMLEkM2r0/edit#gid=0

Resources