Google Sheets Query: Adding Arithmetic Sequence Creating #N/A

Viewed 570

I have this:

=query(Data, "SELECT A, B, sum(E), avg(D), sum(D), sum(F), sum(D)-sum(F) GROUP BY B, A ORDER BY A asc LABEL sum(E) 'Total Daily QTY', sum(D) 'Gross Daily Sales', sum(F) 'Daily Promotion Discounts', sum(D)-sum(F) 'Daily Gross Profit'")

I need to add one more column to the query with this format:

(sum(D)-sum(F))/sum(E)

Which gives me this:

=query(Data, "SELECT A, B, sum(E), avg(D), sum(D), sum(F), sum(D)-sum(F), (sum(D)-sum(F))/sum(E) GROUP BY B, A ORDER BY A asc LABEL sum(E) 'Total Daily QTY', sum(D) 'Gross Daily Sales', sum(F) 'Daily Promotion Discounts', sum(D)-sum(F) 'Daily Gross Profit'")

However, the result is #N/A. I'm not sure if it's creating a sort of circular reference and causing it to break? I tried separating it into an arraryformula, but couldn't get that to work properly either.

Can someone tell me how to get that added column in there correctly? Thank you!

1 Answers
Related