Mathematical order of operations problem? or something else? - google-sheets

Sample gsheet
https://docs.google.com/spreadsheets/d/1lRs27-1vcF-8SV8l2lwOHYtEVJewn7iurqm93C-KtcI/edit?usp=sharing
I think this two formula below supposed to give the same result, and it did when calculate separately. But when I composed the formula together with other cells, it gives 2 difference result. Somebody could explain the logic behind please? Thank You!
=SUM(ARRAYFORMULA($C$5:$C10*$D$5:$D10*$E$5:$E10))-SUM($F$5:$F10)
=SUM(ARRAYFORMULA($C$5:$C10*$D$5:$D10*$E$5:$E10-$F$5:$F10))

Logic is simple - for first formula:
=H2+I2+J2-SUM(ARRAYFORMULA($C$5:$C10*$D$5:$D10*$E$5:$E10))-SUM($F$5:$F10)
replacing ranges with values you get:
=79,478.14 - 41,000.00 - 64.16 => 38,413.98
for second formula:
=H2+I2+J2-SUM(ARRAYFORMULA($C$5:$C10*$D$5:$D10*$E$5:$E10-$F$5:$F10))
with values you get:
=79,478.14 - 40,935.84 => 38,542.30
You should use parentheses to get the same result:
=H2+I2+J2-(SUM(ARRAYFORMULA($C$5:$C10*$D$5:$D10*$E$5:$E10))-SUM($F$5:$F10))
with values :
=79,478.14 - (41,000.00 - 64.16) => 38,542.30

Related

How to find out sum of multiplication of 2 column based on value of a third column?

Silly Q, plz help
I am trying to find of Total invested amount for open positions in my PF. which is like
sum( if(G3="","",D3xE3)+if(G4="","",D4xE4)+..+.........)
How to write a formula for the same.
Thanks.
Try SUMPRODUCT() like-
=SUMPRODUCT(D3:D100,E3:E100,G3:G100="")

How to use arrayformula in googlesheet to count the column with condition?

Hi everyone,
I'm trying to count the number of "Yes" appeared in each row. I want to use array formula so that I'm not required to have formula in each cell in column G. May I know arrayformula can achieve this or there is other method? I tried to use arrayformula(countif(B4:F4,"Yes")) but nothing come out for row 5,6,7,8. Hope to get some advice on this problem as I'm new to google sheet. Thank you.
Give this a try.
=ARRAYFORMULA(COUNTIF(IF(B4:F="Yes", ROW(B4:B8)), ROW(B4:B8)))
Edit: For the case that you describe below (only including certain columns), it's a little more involved, but the same principle works.
=ARRAYFORMULA(COUNTIF(IF(B4:B="Yes", ROW(B4:B8)), ROW(B4:B8)) + COUNTIF(IF(D4:D="Yes", ROW(D4:D8)), ROW(D4:D8)) + COUNTIF(IF(F4:F="Yes", ROW(F4:F8)), ROW(F4:F8)))

Formula that will skip one column when calculating SUM() or similar functions

I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))

How to ignore text/strings in google sheet Sum calculation?

If I have a Text in a sum calculation which I would like to ignore. On the picture below you can see my formula. The text OFF is throwing an error on total hours for me. Any help is appreciated.
Your SUM function is pointless the way you have written it as you're already calculating the result with + and - operators (which is why you get the error). Try:
=SUM(C4,E4,G4,I4,K4,M4,O4)-SUM(B4,D4,F4,H4,J4,L4,N4)
Another approach:
=SUMIF(B3:O3,"End",B4:O4)-SUMIF(B3:O3,"Start",B4:O4)

LOOKUP in Google spreadsheet oddly applied to row

I can't make lookup working properly when used in rows. Where am I wrong ?
See my attempt in the following image
Why are you using LOOKUP? It's very limited in its capability.
To answer your question; it's not working because the LOOKUP requires that the search range is in ascending order, i.e. A - Z in your lookup range you go from a - z - e and this is why it's not working.
You should use the HLOOKUP instead, try this formula instead: =HLOOKUP(D2,$A$2:$C$3,2,0)
Try this:
=HLOOKUP(D3,$A$2:$C$3,2,0)

Resources