TEXTJOIN only when the condition is met?

user234568 picture user234568 · Aug 15, 2017 · Viewed 16.7k times · Source

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

Answer

James D picture James D · Aug 15, 2017

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))