Google-sheets – Matrix multiplication-esque concatenation

google sheets

I'm making a simple recipe maker in google docs, using row vectors and sumproduct I can get it to calculate the protein and calories for a given recipe. The way it's set up it can be hard to read the recipe so I would like to implement something that can add the strings of the ingredients and amount of it then add all those to create a recipe string.

As you can see I need it to concatenate the number in a given row by the ingredient and then concatenate all of them. For example "Recipe in this row" should say "1 dl milk, 1 dl proteinpowder, 1 egg". I get how to do this for a fixed number of ingredients but I want to be able to add ingredients and would need to have some type of running index. I'm new to spreadsheets and have no idea how to do it.

Best Answer

My initial idea is to do something like this: =IF(B2>0, CONCAT(B2,B1)&", ", "")&IF(C2>0, CONCAT(C2,C1), ""). This example only does 2 columns. Add more if statements for more columns. There is probably a better way to do this, but hopefully this gives you an idea of how you could solve this.

This puts the full recipe in one cell.