Combining INDEX(MATCH()) with ARRAYFORMULA() fails - google-sheets

I need a formula for the VariantAttribute column, which fills in the ProductAttribute value based on the first 4 characters of the VariantID
Desired result:
ProductID
ProductAttribute
VariantID
VariantAttribute
ABCD
blue
ABCD-xx
blue
BCDE
black
ABCD-yy
blue
CDEF
orange
BCDE-vv
black
DEFG
blue
BCDE-ww
black
CDEF-uu
orange
DEFG-zz
blue
ABCD-uu
blue
I tried to combine ARRAYFORMULA() with INDEX(MATCH())but failed, obviously because I'm not able to specify a search range within ARRAYFORMULA()
How can I get the desired result?

Assuming the dash ("-") is consistent.
=ARRAYFORMULA(IF(D2:D="",,VLOOKUP(INDEX(SPLIT(D2:D,"-"),,1),A:B,2,0))

Related

Count values in row where first column is value

I would like to create a formula that counts the times the column contains "blue" when the name is "Anna"
In this example that would be a total of 3.
Anna
Krijn
Fieke
Anna
Krijn
Fieke
blue
green
blue
green
blue
green
green
blue
green
blue
green
blue
blue
green
blue
green
blue
green
I've tried COUNTIFS, but couldn't get it to work because the name appears multiple times in the first row.
the setup in the screenshot should be helpful in what the formula is aiming at:
=COUNTIF(IFERROR(FILTER({A2:F},A1:F1=H2)),I2)
or to place it more directly:
=COUNTIF(IFERROR(FILTER({A2:F},A1:F1="Anna")),"blue")
use:
=SUMPRODUCT(FILTER(A31:F; A30:F30="Anna")="blue")

Get the corresponding non-empty adjacent cell in a column in Google Sheets

I'm trying to find the formula for column "C" in order to obtain this:
A
B
C
1
blue
flower
blue
2
water
blue
3
sky
blue
4
green
grass
green
5
frog
green
6
yellow
lemon
yellow
7
sun
yellow
I've tried with INDEX and MATCH but I haven't found yet the way to go.
Bonus: a unique formula with ARRAYFORMULA would be very nice for my use case.
Given the exact layout and ranges shown in your post, delete everything from Col C and place this array formula in C1:
=ArrayFormula(IF(B2:B="",,VLOOKUP(ROW(A:A),FILTER({ROW(A:A),A:A},A:A<>""),2,TRUE)))
This will lookup each row number for rows where Col B is not empty within a virtual array of only those row numbers where Col A is not empty paired with the value of Col A, and return the result from the second column of that array. Because the final parameter of VLOOKUP is TRUE, any exact row number searched and not present in the limited virtual array will "fall backward" to the last row number that was occupied.
I guess you are looking for this
=ArrayFormula(if(row(A1:A) <= max(if(not(isblank(B1:B)), row(A1:A))),vlookup(row(A1:A),filter({row(A1:A),A1:A},len(A1:A)),2),))
Another way
=ArrayFormula(if(B2:B="",,lookup(row(A2:A),row(A2:A)/if(A2:A<>"",1,0),A2:A)))

Using conditional formatting to shade alternating groups of cells of variable size

I am facing an issue where I need to shade a row of cells either blue or orange based on if the user has check-marked the "swap" cell.
Essentially, the rows will start blue and continue to be blue.
When the user presses the checkmark in the Swap column, all rows after that point will now be orange.
Once again, if the user presses the checkmark in the Swap column (below the above checkmarks), the rows will go back to being blue from that point on.
This will alternate forever, as demonstrated in this image.
I am using some conditional formatting code that uses a "helper" column that is hidden. If the value is 1, then the row is coloured orange. If the value is 0, it is coloured blue. The problem is I don't know how to "search" for groups of checkmarks. Each checkmark will only colour the individual row it is in.
The helper column has this code: =MOD(IF(ROW()=2,0,IF(D25=D24,E24, E24+1)), 2)
The D column is where the checkmarks are, and begins at D24.
The E column is my helper column and begins at E24.
I can scrap this whole setup if someone can guide me into how to set this up.
I need it to essentially "change" the values of every row below a checkmark, until it finds another checkmark, and do the reverse so that the colouring can properly format.
Assuming 0:00 is in A1, please select ColumnsA:C and: (i) fill all with 'standard' fill blue and (ii) Format > Conditional formatting..., Format cells if... Custom formula is and:
=isodd(COUNTIF($C$1:$C1,TRUE))
with brown highlighting.

Merge values of an array into a single cell

I have an array that I would like to put into a single cell, with commas to make a list. I'm starting with an array of varying length in column BY:
Red
Blue
Green
Yellow
Purple
Brown
White
Black
Orange
and I want to have all of these put into a cell so it reads, "Red, Blue, Green, Yellow, Purple, Brown, White, Black, Orange"
The list is dynamic, so sometimes it will be just 1 color and other times it may have 50 colors.
I was trying things like,
=concatenate(arrayformula('1'!BY1:BY))
but that returns RedBlueGreenYellowPurpleBrownWhiteBlackOrange
Any ideas for me? Thank you in advance!
NJD
The function you want is join, as in
=join(", ", BY1:BY)
or, since you probably want to exclude empty cells at the bottom of that column,
=join(", ", filter(BY1:BY, len(BY1:BY)))
where filter keeps only nonempty cells.

Filter rows based on uniqueness of a column

I'm sure I'm overthinking a problem again. All I'm trying to achieve is a result array that only contains rows where the data in first column is unique and sorted.
So using an example array (say sheet 'DB')
A B C D
Me Pink Car Top
Me Blue Bike Middle
You Pink Car Bottom
They Pink Bike Bottom
You Blue Bike Top
Them Red Car Middle
Them Blue Car Top
Me Bike Middle
You Car
Us Top
Results in another sheet (say 'Results')
A B C D
Me Pink Car Top
Them Red Car Middle
They Pink Bike Bottom
Us Top
You Pink Car Bottom
Ideally a single formula will go in 'Results!A1'.
Ignoring the SORT element for the moment, this sledgehammer only works for small arrays
=filter(A1:D13,mmult((A1:D13=transpose(A1:D13))*(row(A1:D13)>=transpose(row(A1:D13))),row(A1:D13)^0)=1)
but my DB table is 25,000+ rows (10+ wide) so seems to break the GS 2m cell limit (>matrix 1414*1414) - large arrays produce a 'Column expected 21,414, actual column 1' type error - rather than a more useful 'You broke a limit!'
Note. The above solution works best so far because the originating data is not sorted.
I've tried QUERY() but again, breaks on the UNIQUE() element.
=Query('DB!A2:I, "select * where Col1 matches '"&UNIQUE(DB!A2:A)&"'",0))
error 'No Col1/A'
UNIQUE(...) works fine in terms of stripping duplicates in the key column but how do I then express the rest of the row to each unique entry?
UNIQUE({A1:A;FILTER({A1:D...)}) results in 'No values found'
I was hoping a simple SORT(UNIQUE(...)) would be the ideal solution but alas it seems I'm looking in the wrong haystack.
I've also tried the following structures but either the length of time taken to process or my syntax has crippled any result.
The resulting array btw will just be a helper array for a more rational user sheet that will use IMPORTRANGE() on the result above.
thx to Yogi-Anand for the first solution.
This should do the trick for the above data:
=sort(iferror(ARRAYFORMULA(VLOOKUP(UNIQUE(A2:A),A2:D,{1,2,3,4},false)),""),1,true)
Gives the following result:
Me Pink Car Top
Them Red Car Middle
They Pink Bike Bottom
Us Top
You Pink Car Bottom
if you have more columns you need to be included in your vlookup you can add it like so:
VLOOKUP(UNIQUE(A2:A),A2:(till which Column),{1,2,3,4,5... (Add your columns here)},false
However, note Vlookup will return the first row corresponding to the match in Column A. That means the order of the data in the input array matters.
Hope that helps!
This formula accomplishes this:
=ARRAYFORMULA(if(istext(SORT(UNIQUE(Sheet3!A:A))),arrayformula(VLOOKUP(SORT(UNIQUE(Sheet3!A:A)),Sheet3!A:D,{1,2,3,4},false)),))

Resources