11

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

user234568
  • 741
  • 3
  • 11
  • 21

2 Answers2

13

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))
James D
  • 3,102
  • 1
  • 11
  • 21
4

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,"")))
Jeremy Kahan
  • 3,796
  • 1
  • 10
  • 23