Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TEXTJOIN only when the condition is met?

I tried using TextJoin function with IF in it, but it somehow doesn't seem to work. I think I've written the formula correctly, but it doesn't give the solution I'm attempting to get.

Objective: I want the values from A-column to get printed out only when the values of B-column matches with the value of D-column. The intended outcome should be 1,2,3,6

Does anyone know how can I get done? Did I do something wrong? By the way, I'm using the google spreadsheet.

enter image description here

like image 338
user234568 Avatar asked Aug 15 '17 02:08

user234568


2 Answers

Your formula works you just need to enter it as an array formula, hold ctrl + shift and press enter to make it an array formula. It should look like:

=ArrayFormula(TEXTJOIN(", ",true,if(B1:B6 = D1,A1:A6,"")))  

You could also use the filter function

=TEXTJOIN(", ",true,FILTER(A1:A6,B1:B6 = D1))
like image 100
James D Avatar answered Nov 03 '22 05:11

James D


The if is just giving one result, not a series of them. You need:

=textjoin(" ,",true,arrayformula(if($B$1:$B$20=$D$1,$A$1:$A$20,"")))
like image 39
Jeremy Kahan Avatar answered Nov 03 '22 03:11

Jeremy Kahan