How do I reverse an array in Google Sheets? - arrays

Suppose I have a long, unordered, and gradually growing column that I search the even numbers from.
=filter(A1:A,ISEVEN(A1:A)=TRUE)
Now I would like to reverse this result, so that the last even number in column A is listed first in the result. Many examples use helper columns or the row function, but that doesn't seem to be an option because you don't know how many even elements there are in this array before you begin. And even if I separately calculate that using rows I can't seem to figure it out. It seems like there should be a rather simple way to just "reverse" an array right?

use:
=INDEX(SORT(FILTER({A1:A, ROW(A1:A)}, ISEVEN(A1:A), A1:A<>""), 2, 0),, 1)

Try this:
=QUERY(FILTER({A:A,ROW(A:A)},ISNUMBER(A:A),ISEVEN(A:A)),"Select Col1 Order By Col2 Desc")

Related

How to use Lambda in Excel to return array of results for an array

I am becoming more and more familiar with Excel's new array functionality and absolutely love the direction it is all headed.
I've been trying to find a way to have a single formula which will spill an array of multiple columns, each which correspond to the proper SKU in column A.
In order to achieve this currently, I just write a formula like this, then I drop the formula down to the bottom of the data.
=XLOOKUP($A2,SKUP[SKU],HSTACK(SKUP[SKU Desc],SKUP[Package Desc],SKUP[Supplier]),"Not Found",0)
I just recently learned about LAMBDA formulas and trying to learn more about them. I was wondering if there is any way I could change this formula to reference all SKUs in column A, instead of having to use just 1 SKU at a time for this calculation?
I was thinking of something like this:
=LAMBDA(sku_array,LET(r,ROW(),s,INDEX(sku_array,r),XLOOKUP...
However, each attempt I've tested with something similar just seems to give errors. If I change the original XLOOKUP formula making the search value the whole column, it still only results 1 column.
Why not just HSTACK first then FILTER the result?
=FILTER(HSTACK(SKUP[SKU Desc],SKUP[Package Desc],SKUP[Supplier]),ISNUMBER(MATCH(SKUP[SKU],A2:A100,0)))

non-unique function

Here's the sheet: https://docs.google.com/spreadsheets/d/1NCxpNFIdb-DAn4e259KRfPF8o_rv9O9KY4wOdCG6AM8
I managed to get the unique output. Another question, is there any way to get the non-unique output with a formula? I tried to search online but most said not possible :/
So I have a whole column of random numbers+alphabets (Upper and lower cases) like this: 7hyOUGvag1 in column A and I tried to apply unique(A: A) for the whole 4000+ rows in column A but it didn't give me the unique output of it, but instead it gave me duplicates of the same output still. Why? I searched everywhere but everyone seems to have no problem with the simple unique function but for me, it didn't work properly...
Is it because my rows of values are randomized with upper and lower cases alphabets + random numbers too?
try:
=INDEX(UNIQUE(LOWER(A2:A)))
the LOWER can be replaced to UPPER or PROPER
if you don't want to convert it to either of those modes mentioned above try:
=INDEX(UNIQUE(IFNA(VLOOKUP(A2:A, A2:A, 1, 0))))
To get non-unique values (duplicate) you can also use:
=FILTER(UNIQUE(A2:A), ARRAYFORMULA( COUNTIF(A2:A,UNIQUE(A2:A))>1 ))
Functions used:
FILTER
ArrayFormula
UNIQUE
COUNTIF

Can I make an array out of a range of countif functions?

A truncated version of my data is in the form shown in the screenshot below: three columns of 5 unique names. The names appear in any order and in any position but never repeat in a single row.
My goal is to create an array that contains the number of times Adam appears in each row. I can fill down the formula=countif(A2:C2,$I$2) in a new column, or if I write the array manually for each row, it looks like:
={countif(A2:C2,$I$2);countif(A3:C3,$I$2);countif(A4:C4,$I$2);countif(A5:C5,$I$2);countif(A6:C6,$I$2)}
Where cell I2 contains "Adam". Of course, this is not feasible for large data sets.
I know that arrays are effectively cells turned into ranges, but my main issue is that the cell I'm trying to transform already references a range, and I don't know how to tell the software to apply the countif down each row (i.e. I intuitively would like to do something like countif((A2:C2):(A99:C99),"Adam") but understand that's not how spreadsheets work).
My goal is ultimately to perform some operations on the corresponding array but I think I'm comfortable enough with that once I can get the array formula I'm looking for.
try:
=ARRAYFORMULA(IF(A2:A="",,MMULT(IF(A2:C="Adam", 1, 0), {1;1;1})))

SUM with IF conditions for cells containing both strings and numbers

I've got a bigger table with one column that I want to focus on, containing designation and a number. I want to simply sum the numbers that meet the criteria based on a designation.
For the simplification, I made an exercising sheet (on the pic) where I split second column into two - one string and one numeric. Since my file is quite large with many columns that would need this it would be inconvenient.
In the left column it's easy to solve the problem, it could be even easier with simple SUMIF function, but an array SUM(IF... function is, at least I think, only viable option here.
So I solved the first table with array function, but what confuses me is how to modulate the TRUE statement. Simple replacement of C:C
with
VALUE(MID(F:F;4;4))
which would format my cells to get the numbers from string does not work that way - returns zero in E12 field. F12 is just application of string to number for last cell, F10.
THIS formula does not work, even adapting to different versions of the tool.
I could use VB but if possible anyhow I would like to avoid it since parts will be shared on mobile phones.
Any ideas? Thanks a lot!
Left table was split, right original format
The array formula which you used can be replaced by the SumIf formula like below...
=SUMIF(B:B,"B",C:C)
Also without the helper column, you can use the Sumproduct formula to achieve the desired output.
But don't refer the whole column in the formula like in the above SumIf formula.
Try this..
=SUMPRODUCT((B1:B10="B")*MID(F1:F10,FIND(",",F1:F10)+1,255)*1)
Change the ranges as per your requirement but remember to make them equal in size.

Nested OR with AND and IF - Excel

Simple question that I wasn't able to figure out. Trying to calculate counts and medians of arrays with a conditional that depends on numbers in two columns in Excel, as seen below.
=MEDIAN(IF(AND($D$3:$D$1216=1,OR($B$3:$B$1216=3,$B$3:$B$1216=6,$B$3:$B$1216=9,$B$3:$B$1216=12)),$M$3:$M$1216))
Please see above for the function, which I input as an array. All I'd like to do is scan Column D for all 1s and then 3/6/9/12 in Column B.
The function works but only returns zeroes for all relevant values in Column D, which I find strange.
Thank you for your help!
Is 0 in fact the most common element in $M$3:$M$1216? i.e., are a lot of those cells just blank?
When I keep the range large, but only enter a few values, I get the same result as you. When I shrink the range to something more manageable, and fill in the values, the function returns what I'd expect.
Also, here's a somewhat simpler syntax for the same result:
=MEDIAN(($D$3:$D$5=1)*OR($B$3:$B$5=3,$B$3:$B$5=6,$B$3:$B$5=9,$B$3:$B$5=12)*($M$3:$M$5))

Resources