Sum values if any cell in corresponding row matches text - google-sheets

I have the following Google Sheets data:
Name1 Name2 Name3 Value
A B C 20
B A C 30
C D F 40
What I'm trying to do is see if a specific name appears in any of the three name columns. If it does, then sum all the values in the "Value" column for all matching rows.
For example, I want to sum all of the values for name "A". That name only appears on the first two rows, so it should do 20+30 to give me 50. If I change the searched name to "C", that appears in all three rows so it should sum all of the numbers: 20+30+40. The algorithm needs to adjust and search appropriately.

=DSum will work
With the example you give use
=dsum(A1:D4,D1,{A1;"A"})+dsum(A1:D4,D1,{B1;"A"})+dsum(A1:D4,D1,{C1;"A"})
You can swap the "A" for a Cell reference
see https://drive.google.com/previewtemplate?id=0As3tAuweYU9QdEVHdTFHNzloSTY4LVYxdW9LdHRHbEE&mode=public#

Related

Using Google Sheets ARRAYFORMULA to Concatenate Series of Item Based from Lowest to Highest Values per Row

I have a table with three Columns:
Column A: name of Item,
Column B: Lowest value of series,
Column C: the Highest value of series.
enter image description here
What I want to achieve is:
Generate series of item sequence from lowest number to highest number per row
So Apple 7 9 will yield: "Apple_7", "Apple_8", "Apple_9"
Concatenate/Join such sequence per row into Column D
So
Item
From
Until
Result
Apple
7
9
"Apple_7, Apple_8, Apple_9"
Berry
3
8
"Berry_3, Berry_4, Berry_5, Berry_6, Berry_7, Berry_8"
Doing it all using one Arrayformula, so that new row added can be automatically calculated.
Here is example sheet: https://docs.google.com/spreadsheets/d/1R5raKmmt5-aOIorAZGHjv_-fdySKWjCMB_FRQwm1vag/edit#gid=0
I tried in Column D:
arrayformula(textjoin(", ",true,arrayformula(A3:A&"_"&sequence(1,C3:C-B3:B+1,B3:B,1))))
Apparently, the sequence function only take value from Column B and join it in first row.
Any help will be appreciated.
Try below BYROW() formula (see your file, harun24hr sheet).
=BYROW(A3:INDEX(A3:A,COUNTA(A3:A)),LAMBDA(x,TEXTJOIN(";",1,INDEX(x&"_"& SEQUENCE(INDEX(C:C,ROW(x))-INDEX(B:B,ROW(x))+1,1,INDEX(B:B,ROW(x)))))))
Here A3:INDEX(A3:A,COUNTA(A3:A)) will return a array of values as well cell reference from A3 to last non empty cell in column A (Assume you do not have any blank rows inside data). If you have blank row, then you have to use different approach. See this post by #TheMaster
Then LAMBDA() will apply TEXTJOIN() and SEQUENCE() function for each cell of B as well as C column.
SEQUENCE() will make series from start to end number and by concatenating A column and will generate your desired strings.
Finally TEXTJOIN() will join all those strings with delimiter to a single cell.
try REDUCE:
=INDEX(QUERY(REDUCE(, A3:INDEX(A:A, MAX(ROW(A:A)*(A:A<>""))),
LAMBDA(x, a, {x; JOIN(, LAMBDA(i, f, u, i&"_"&SEQUENCE(1, u-f+1, f)&";")
(a, OFFSET(a,,1), OFFSET(a,,2)))})), "offset 1", ))

SUMIFs multiple criteria is not working consitently

I am using Google Sheets with the spreadsheet shown below.
I want to Sum the 'Amount' column
IF the Key in column J == the key in column B
AND The Assigned person == the actual person.
So, where the key is 2, we'd have a subset of 7 items. From that the assigned person is Sally and four entries match, our total would therefore be the sum of those matching values which are 20, 10, 2, 4 giving a sum of 36.
In K3, we can correctly see the sum of 36.
The formulae I used in that cell is:
=SUMIFS(H:H,B:B,J3,G:G,D:D)
The cell below has the formulae:
=SUMIFS(H:H,B:B,J4,G:G,D:D)
So, that should, I believe sum the values 3,8 and 4 since the key (3) in column J matches three items in column B. In each case Mike is the assigned and actual person, which means we should be summing 3, 8 and 4. However, the value as you can see is 0.
Any ideas what I'm doing wrong, please?
You can also do this with a single formula in Google Sheets;
=query(B2:H," select B,sum(H) where D=G and B is not null group by B label sum(H) ''")
Use SUMPRODUCT:
=SUMPRODUCT((B$2:B$13=J2)*(D$2:D$13=G$2:G$13)*H$2:H$13)

Get MIN value for each type from an unsorted dataset with multiple types using Google Sheets formula

In col A, I have a mix of data that starts with a data type identifier, followed by a value, all semi-colon separated e.g.
a_3;b_2;c_4;c_5;b_2;a_1;a_7;b_9
In col B, I have just the data type identifiers listed in the following manner:
a;b;c
In col C, I am struggling to write a formula that would return the minimum number value for each of the corresponding data types in col B.
So, as per above, the values are a_3;a_1;a_7, thus the minimum value for 'a' is "1". Likewise minimum for 'b' is "2" and the minimum for 'c' is "4".
The return value to be displayed in Col C would thus be:
1;2;4
I wrote an ARRAYFORMULA that creates a 2d array where its first row only contains 'a' values, row two only has 'b' values and row three has 'c' values.
e.g.
3 1 7
2 2 9
4 5
But I have no idea how I can feed each separate row to a MIN function (which would itself have to be inside some kind of array formula that would iterate over the above array one row at a time).
Maybe this is a flawed approach and I need to think about the solution differently.
to summarize:
Col A Col B Col C
a_3;b_2;c_4;c_5;b_2;a_1;a_7;b_9 a;b;c 1;2;4
I need the formula to produce the result in Col C.
Here is the example sheet:
https://docs.google.com/spreadsheets/d/1k1K7_msW8Jd_9-18zKdgdFKsSSYrRLtYjTLolQsAVjQ/edit#gid=0
=TEXTJOIN(";",1,ARRAYFORMULA(IFERROR(VLOOKUP(TRANSPOSE(SPLIT(B2,";")),
SORTN({REGEXEXTRACT(TRANSPOSE(SPLIT(A2,";")),"[A-Za-z]+"),
REGEXEXTRACT(TRANSPOSE(SPLIT(A2,";")),"\d+")},COUNTA(TRANSPOSE(SPLIT(A2,";")))),2,0),)))

Query values from separate sheet

I am trying to figure out how to query values from Sheet2 into Sheet1 where column A in Sheet1 matches column A (strings) in Sheet2, and return only the max value of column D (integer) from Sheet2.
Here's what I am using:
=Query(Sheet2!A:F,CONCATENATE("Select D where Name =",A2))
I have tried using Select max(d)... and =MAX(Query(...)) but neither worked for me.
What would be the correct way to do this?
Example data:
Sheet1
Name ColB Date Check Oldest
Bob Y 2/14/2013 4/14/2013 5
Sheet2
Name Title Date Age
Bob Foo 2/1/2013 3
Boo Bar 2/4/2013 5
This may serve, if entered in the cell presently containing Oldest (which would then be overwritten with max Age:
=query(Sheet2!A:D,"select max(D) where A ='Bob' ")
but the result for your sample would be 3 rather than the 5 as shown to be required.

Lookup value based on latest matching criteria

Below is an example of a table I have, what I am trying to do is get the value in the value column for a specific criteria based on the last occurrence (not including today's date).
So in the example below I want to find the value for the last occurrence of 'A', which is 12.
I think this can be done using an Index-Match, I just can't get my head around it though.
For example
Todays Date: 15/12/2013
---------------------------------|
|Date | Criteria | Value
|--------------------------------|
|12/11/2013 | A | 3 |
|16/11/2013 | B | 6 |
|27/11/2013 | C | 7 |
|3/12/2013 | A | 12 |
|5/12/2013 | B | 8 |
|15/12/2013 | A | |
----------------------------------
EDIT:
I would also like to add that this formula will be in a different sheet to the table above. The sheet reference in the formula also needs to be dynamic, it will draw the sheet name from another cell.
I would use this formula:
=index(C:C,max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))),1)
This formula assumes that your data is in the columns A,B,C and for every "A" value in the Criteria column, the Date is different. (If that's not the case, then this formula won't work, see below.
Let's look the formula inside from outside:
filter(A:A,B:B="A",C:C<>"") - This will result with the dates where there is an "A" in the Criteria column, and where the Value column is not empty.
arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0)) - In this step we basically find the row number in which those dates are present. The match function will search for the dates (counted in step 1). The arrayformula is needed because there will be more results.
max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))) - This will find the maximum row number (The maximum row number which contains an "A" in the Criteria column)
index(C:C,max(arrayformula(match(filter(A:A,B:B="A",C:C<>""),A:A,0))),1) - Finally, we use the INDEX function to navigate to the value, which has the maximum row number.
Now, if you want this formula to work on another sheet, you should write, instead of for example:
=index(C:C,... => =index(Data!C:C,...
Assuming that your data is in your Data worksheet.
If you want to this sheet to be dynamic, it's a bit tricky. Let's assume, that you're getting the value of the sheet name from the G1 cell. Then you should write:
=index(indirect(concatenate(G1,"!C:C")),...
This is not so pretty as you should do this for every occasion when it occurs in that long formula (described earlier). Instead you can do some pre-work.
Let's write this to your H1 cell: =concatenate(G1,"!C:C") - If in the G1 cell the sheet name is "Data", then the H1 cell should contain: Data!C:C, similarly you can add to the
H2 cell: =concatenate(G1,"!A:A"),
H3 cell: =concatenate(G1,"!B:B")
Now you can write (and that's the final answer for your question I think):
=index(indirect(H1),max(arrayformula(match(filter(indirect(H2),indirect(H3)="A",indirect(H1)<>""),indirect(H2),0))),1) - where H1,H2,H3 will reference to your Data sheet's columns.
I hope it helps.
Use the following formula to accomplish that.
Formula
=QUERY(
B1:D6, // data
"SELECT D // select
WHERE // where clause
C = 'A' AND // first criterium
D IS NOT NULL // second criterium
ORDER BY B DESC // order by
LIMIT 1, // limit
0" // headers
)
for copy/paste
=QUERY(B1:D6, "SELECT D WHERE C = 'A' AND D IS NOT NULL ORDER BY B DESC LIMIT 1", 0)
Explained
The clue to the formula is the usage of the ORDER BY and the LIMIT options within the QUERY formula. The WHERE clauses will prepare the result in the first place. Next, column B (the dates) is ordered descendingly (highest first). The LIMIT option sets the amount of rows to be displayed at 1.
Example
I've created an example file for you: Lookup value based on latest matching Criteria
I appreciate this is a slightly old question, but there is a way that I achieved the goal of filtering an array which I found both more conceptually straightforward, and also more generally applicable than the other answers I have seen, using vlookup's definitional ability to pick the first matching value in an array.
PROBLEM, RESTATED:
Assuming sample data:
A...B...C...D...E, created by a google form
A is the form entry date
B, C and D are entries from a list (let's assume they are e.g. product name, geography, and sales date)
E is the value
If a new value is entered for a particular product, in a geography, on a date, then I want this to be used in preference to the older version of that same data.
SOLUTION:
If, in your form, you create three new columns:
F Unique test
G Test cells combined
H Unique cells
Then in column G, you create a combination of all the cells you want to test on (in this case B, C and E)
cell G2: "=arrayformula(B2:B & char(9) & C2:C & char(9) & D2:D)"
The next column is a restatement of the cells you want to filter based on (in this case the date in A)
cell H2: "=arrayformula(A2:A)"
And then finally in column F we actually undertake the test:
cell F2: "=arrayformula(A2:A=vlookup(G2:G,sort({G2:H},2,false),2,false))"
Breaking that down, the vlookup (vlookup(G2:G,[RANGE],2,false) compares the data in G2, G3...Gn with a [RANGE], which is a virtual array consisting of two columns, G and H, pre-sorted according to cell H in descending order.
i.e. For any unique value of G (the combination of test data) the vlookup will return the largest value of H
The last part is a simple comparison to the original data (A2, A3... An) to return TRUE or FALSE based on whether it is the latest version of the unique value.
A final step if needed would be to create a new sheet with "=filter('Form Responses 1'!A:E,'Form Responses 1'F:F=TRUE) to recreate the data without the older versions.
Hope this helps.

Resources