Search code examples
arrayssortinggoogle-sheetsuniquegoogle-query-language

Adding an additional row of data based on condition - Google Sheets


I'm trying to create a formula that adds a row of data based on the value in another cell. So far I've only managed to create a formula that will duplicate the row of data but I don't think I'm on the right track with this.

https://docs.google.com/spreadsheets/d/1J0ATk-aoEN7FHhLaGjxWZQx6n0sPAPTIGKNofdotP-w/edit?usp=sharing

enter image description here

Each row is made up of a unique order number which repeats if there's more than 1 item purchased, the items are then specified in column C. I would like to add an additional line to each order that contains the word "Shipping" in the Item Name column but only when the shipping cost is >0, I would also like the shipping cost to appear on the additional row.

Any help at all on this would be hugely appreciated!


Solution

  • try:

    =SORT({UNIQUE(QUERY(QUERY({A3:C}, 
     "select Col1-0.99999999999,'Shipping',Col3 
      where Col3>0"), "offset 1", 0)); A3:C}, 1, 0)
    

    enter image description here