Sum cells if date is correct (SUMIF) - google-sheets

I am having a little problem with Google Sheets. My sheet looks like this:
A B C
24.11.2014 07:30:12 Fruit 500
24.11.2014 17:34:32 Meat 450
25.11.2014 07:30:09 Blah 1000
25.11.2014 18:30:47 Blah 802
Now I want to add the numbers in C:C if the date equals 24.11.2014. My first guess was using:
=SUMIF(A:A,">="&E2,C:C)
Where E2 = 24.11.2014
After messing around with it, it still gives me a parsing error. SUMIF usually works with Google Sheets.

Here is the simplest solution:
=SUMIF(A:A;"*"&E2&"*";C:C)
you sum the values in C:C if you find E2 in A:A. and the result 950 in this example. Hope this works fine.

After changing to the right argument separator (for the locale of the OP) the original formula seemed to work:
=SUMIF(A:A;">="&E2;C:C)

Related

Using a concatenated string in Google sheets query WHERE condition

I am trying to use the result of a concatenation of a string and cell contents in a query, but the query function does not seem to like it: see this example
https://docs.google.com/spreadsheets/d/1CtPFLhpD3KDHrk-6WoHft4JdMTVa3OcvHHqAidMWwdM/edit?usp=sharing
The strings in cells B2 and B3 appear to be the same, but whilst C3 gives the desired result, C2 does not. B3 simply extracts a string from A3, whereas B2 tags the 'E' on in the formula. The data in the real spreadsheet I am working with is like that in B2, so I have to add the 'E' into the result. The real list of error codes is quite long and varied, so I cannot edit that to just use the number. I also tried using CONCATENATE, but that made no difference.
How do I get the query to recognise the contents of C2 as the string 'E151'?
Most likely there's an trailing space in the result of B2.
See if this helps
=query(A7:B10,"select B where A = '"&trim(B2)&"'",0)
In B2
="E"&mid(A2,30,3)
or
="E"&index(REGEXEXTRACT(A2,REGEXREPLACE(A2,"(\d+)","($1)")),1,5)
(the 5th number in the string)
delete everything in column C and use this in C2:
=INDEX(IFNA(VLOOKUP(TRIM(B2:B4), A7:B11, 2, 0)))
Some great answers to my question, thanks! It was a trailing space causing the problem.
I have combined some of the ideas in the other answers in the real spreadsheet and used
="E" & trim(mid(A2,30,3))
Since some of the error codes are only 2 characters long

Referencing a cell's row value using a formula

Suppose my excel sheet looks like this:
Name
Houses
Cars owned
column D
John
3
3
=A&MAX(30,3)
Harry
2
4
..
Vik
5
1
..
..
p
k
..
...
q
n
..
In column D, I want to return the row in column A that corresponds to the larger of the two values in cells B2 and C2. So in cell D2, I would want to return "Vik" because the larger of the two values in B2 (3) and C2 (3) is 3. And the value in cell A3 is Vik.
So in order to arrive at my result, I would input something like ="A"&MAX(B2,C2) in D2.
But suppose my formula was a lot more complex and with different data.
=IFERROR(ArrayFormula(ADDRESS(MAX(index(IF($A$1:$D6=B7,ROW($A$1:$D6),""),,IF($A$1:$D6=B7,COLUMN($A$1:$D6)),"")),MAX(IF($A$1:$D6=B7,COLUMN($A$1:$D6),"")))),"")
and I wanted the result of the first chunk of the formula (from ADDRESS() onwards)
MAX(index(IF($A$1:$D6=B7,ROW($A$1:$D6),"") (which is 3, say) to be the row number that is input into
MAX(IF($A$3:$D3=B7,COLUMN($A$1:$D6),"")) for the range inside the IF condition.
(notice how $A$1:$D6 changed to $A$3:$D6)
So, going by the tabular example above, I would simply input MAX(IF("$A$"&MAX(index(IF($A$1:$D6=B7,ROW($A$1:$D6),""):$D6=B7,COLUMN($A$1:$D6),"")) and that should do the trick. Except it doesn't and I get a formula parse error which I cannot resolve.
Here is the specific excel sheet I'm working on: https://docs.google.com/spreadsheets/d/12U8U7Jp4FscobIvgr4_sADJB_oSdIHrboCk02cxF_u0/edit?usp=sharing
Can anyone see what I'm doing wrong? The solution, I think, should be simple enough but I can't seem to figure it out.
Sorry if it's a bit long but I've been struggling with this for a while now.
I hope this formula will help
=ARRAYFORMULA(IFNA(VLOOKUP(QUERY(TRANSPOSE(QUERY(TRANSPOSE(B2:C6);"select "&JOIN(",";"max(Col"&row(B2:C6)-1&")")));"select Col2+1 label Col2+1''");{row(A:A)\A:A};2;False)))
Solved using the indirect function and ampersand concatenation.
New function would be: =IFERROR(ArrayFormula(ADDRESS(MAX(index(IF($A$1:$D6=B7,ROW($A$1:$D6),""),,IF($A$1:$D6=B7,COLUMN($A$1:$D6),""))),MAX(IF(INDIRECT("$A$"&(MAX(index(IF($A$1:$D6=B7,ROW($A$1:$D6),""))))):$D6=B7,COLUMN($A$1:$D6),"")))),"")

Adding or subtracting values based on a vector of check boxes in Google Sheets

I hope you can help me with this:
I'm trying to create a savings-control sheet where I list my monthly payment and I'm trying to use the SUMIF formula to subtract my expenses by selecting what I have currently payed but I don't know if this may work with a vector of check boxes Sheets sample
the current formula as you can see in the image works fine but only for column D however if I check the rest of the boxes nothing is subtracted
This is how the formula looks like now: =A31+A32-SUMIF(D3:J14,TRUE,C3:C14) however only works from D3 to D14 and I need it to work from D3 to J14
Any help will be highly appreciate
I think the simplest solution is:
=A31+A32-SUM(ARRAYFORMULA(N(D3:J14)*C3:C14))
Formula rundown
This formula is based on the function N that converts a boolean to an integer (1 for true, 0 for false). We can then multiply by the expense value. Here an example:
=N(D3)*C3
This will equal C3 iff D3 is checked.
Having that we can make the entire table with ARRAYFORMULA:
=ARRAYFORMULA(N(D3:J14)*C3:C14)
Now we can sum all the values to have the total expenses:
=SUM(ARRAYFORMULA(N(D3:J14)*C3:C14))
Add the other cells and you get your result.
References
N (Docs Editors Help)
ARRAYFORMULA (Docs Editors Help)
SUM (Docs Editors Help)
Try
=A31+A32-sumproduct((countif(if(D3:J14, row(D3:D14)), row(D3:D14))>0),C3:C14)
and see if that helps?

Sum products in certain conditions

I'm sorry to ask this, I have not any code skills and I've trying to figure that out for a few hours now.. I think an image will be better for you to understand what I want:
I want A2 to show the sum of the products in G:G that fit certain conditions (2020,jan,buy). I haved tried several formulas but I came up with this one as the closest, I think, but still won't work:
=arrayformula(SUMIFS(E:E=B1,F:F="jan",G:G="buy",H:H))
Can anyone explain me how to achieve that?
Thanks very much :)
Please use this formula in A2 it will work
=sumifs(G2:G100,D2:D100,2020,E2:E100,"jan",F2:F100,"buy")
So basically, sumifs formula is right one as you want to check for multiple conditions.
so this is how this formula work
=sumifs(sum_range,criteria_range1,criteria1,criteria_range2,criteria2,...)
In your case your same range is column 'G' so if you have a finite range like only 25 rows you have in your table then instead of G2:G100 you can use G2:G25 as G1 is containing label and make sure that all other ranges also similar to the range of column G. for example if you take range of G2:G100 means 99 rows then you should take E2:E100 or E3:E101(range of 99 rows, that rows must be 99 and series start and end number is as per your requirement, similar case for other columns in this formula)
you have to check 2020 in column D, so you criteria_range1 is of D column I took it D2:D100 and criteria 1 is 2020 as it's a number it doesn't need double quotes
criteria 2 is you need to check Jan in column E so criteria_range2 is column E I took it E2:E100 and criteria 2 is "jan" as it's not a number so I took it in double quotes.
criteria 3 is you need to check 'buy' in column F so Criteria_range3 is column F. I took it as F2:F100 and criteria 3 is "buy" again it's not a number so took it under double quotes.

Understanding "select X where Y = ..." in a google sheets QUERY function

I'm trying to figure out how to parse this google sheets function:
=IFERROR(QUERY($A$2:$F$1000, "select F where A="&A4&" "),"")
I'm having trouble understanding the "select F where A="&A4&" part. The function is applied to an entire column. For some of the rows, this function returns a number, for others it returns a blank. The A column which it is referencing is entirely composed of 6-digit numbers.
What is going on such that sometimes the function returns a number and sometimes a blank?
Also, why are the ampersands important? If I take away the ampersands, the function returns an error.
You need to fix the quotes around A4.
=IFERROR(QUERY($A$2:$F$1000, "select F where A='"&A4&"'"),"")
'"&A4&"'
means what is in cell A4
The & means to concatenate.
In this case the literal contents of A4 into the query formula.
Notice that the query has 4 "s. ie ""
"&""
The single quotes are to make the contents of A4 a string.
where A=
so where contents of A2 to A1000 matches the contents of A4.
It would definitely match on A4, (and any other Col A cell that had the same contents.)
in which case it would return F4 because of the
"select F"
means show/return column F in the results
You should try the following:
=arrayformula(if(eq(F2:F,A2:A),F2:F,))
It is hard to suggest the right formula without seeing what you are working with or what the expected result looks like, so if this doesn't work, please share your sample spreadsheet.

Resources