Search code examples
arraysif-statementgoogle-sheetsgoogle-sheets-formulaarray-formulas

Get the table headers of the cells having quantities and display in bill using google sheet formula


I have a google spreadsheet where I need to fetch the quantities and ordered fruits from the releavnt customer. The headers are expected to be fetched and placed in (yellow cells) based on the bill number(red color cell) choosen.

I have tried with vlookup for fetching the amount and finding total price which works great.

The below screenshot is

For example the bill number 5 is choosen, Matt will be displayed in the bill and using vlookup, and display Apple Banana and Mango to be displayed based on formula

When bill number 2 is choosen Cathy will be displayed and in yellow cells only Banana and Mango will be displayed (apple and pineapple should not be displayed as Cathy didnt purchase them)

Here is the Google sheet: https://docs.google.com/spreadsheets/d/1n2XgoUHZh9GwWGTQP8nvK2MV3uoXzP7s9V7aXLMbOrk/edit#gid=1150750443

enter image description here


Solution

  • use:

    =ARRAYFORMULA(TRIM(SPLIT(QUERY(FLATTEN(TRIM(
     IF((A2:A7=B11)*(D2:G7<>""),D1:G1&" ♦ ♠ ♦"&D2:G7, ))), 
     "where Col1 is not null"), "♦♠")))
    

    0