The solution was that I didn't need to unpivot, just reorder. =query({'Order entry'!A1:E; {'Order entry'!A2:C, 'Order entry'!F2:G}},"SELECT * WHERE Col4 is not null AND Col5 is not null order by Col1") Also added order by Col1 to sort by date.