Search for lowest/highest value in the date array - google-sheets

What is the best formula to get the lowest and highest values from column C for every date?
Need to fill F and G columns as a result
Link:
https://docs.google.com/spreadsheets/d/1IxLit5vOf9FIjEp4TOEWLFNoCB4yS5mYXXMXo2tvtiM/edit?usp=sharing

try:
=ARRAYFORMULA(QUERY({LEFT(A2:A; 10)*1\C2:C};
"select Col1,min(Col2),max(Col2)
where Col2 is not null
group by Col1
label Col1'date'"))

Related

SUM of comma separated numbers for each unique value

I'm trying to return the SUM of a set of numbers, which are comma seperated in another cell.
I'm listing out the unique values in column 1, and trying to SUM the numbers in column 2.
Client A 0,56.3,0,450,90,22.6,22.6,0,180,0,90,67.6,67.6,67.6,90,225,450
The expected outcome is 1879.3 for Client A.
But how can I do this for every new client and set of numbers added? I have tried a combination of SUM and SPLIT, but I can't get it work for every value in column A in an arrayformula.
Here is the file: https://docs.google.com/spreadsheets/d/1k8o_Ft59R44yQKOSY99AuAk8HDGTcRyiw2N9umONv3U/edit?usp=sharing
Thanks!
You could try:
=INDEX(QUERY(SPLIT(FLATTEN(A1:A&"|"&SPLIT(B1:B,",")),"|"),"Select Col1, Sum(Col2) where Col1 is not null and Col2 is not null group by Col1 label Col1 'Client', Sum(Col2) 'Total'"))
I've put the formula in F1 in your spreadsheet:

Countif with last 5 values

I am trying to calculate the last 5 and last 10 values for specific players in a set of data. The date is in column B, players names are in column K, the data I need to count is in column Z. I just want to have a formula that finds the last 5 values associated with a players name and adds them up. Is that possible? I attached the googlesheet for your review! Thank you for the help!
https://docs.google.com/spreadsheets/d/1iR44nAFSUxZ54LOH61zPOGS_6ugYIMYHEfhJM-SkV6k/edit?usp=sharing
since the dates are in descending order all you need is:
=QUERY(FILTER({K2:K, Z2:Z},
COUNTIFS(K2:K, K2:K, ROW(K2:K), "<="&ROW(K2:K))<6),
"select Col1,sum(Col2) where Col1 !='' group by Col1 label sum(Col2)''")

SUMPRODUCT of last nth values with criteria

I have two columns (see screenshot)
How can i create a formula that sum the second LATEST column values with a criteria from column A?
For example i need the sum of the last 6 values (from column B) of the cells (in column A) that start with HH, so values starting from the bottom.
I know how to make a sum of all values (from column B) containing HH (from column A)
=SUMIF(A1:A;"HH"&"*";B1:B)
P.S. HH and * are separate because i'll substitute the HH with a cell
but now i need to delimit this to the last N values (let say last 3 values)
P.P.S.
=SUMPRODUCT((COUNTIFS(A1:A;"exact text";ROW(A1:A)*{1;1};">="&ROW(A1:A)*{1;1})<=3)*(A1:A="exact text");B1:B)
This works so far ONLY if i write the exact text, not with values like HH*
Maybe try
=sum(index(query({row(A1:A), A1:B}, "Select Col3 where Col2 contains 'HH' order by Col1 desc limit 6")))
and see if that works?
Note:
*the string HH can be also be in a cell (ex. D1)
=sum(index(query({row(A1:A), A1:B}, "Select Col3 where Col2 contains '"&D1&"' order by Col1 desc limit 6")))
*6 indicates the number of values you want to sum
EDIT: For your locale you'll need to use in G1
=sum(index(query({row($B$1:$B) \ $B$1:$C}; "Select Col3 where Col2 contains '"&E2&"' order by Col1 desc limit 3")))
and fill down. See if that works?
This should also work, not sure if it's any easier to understand/ less complicated than any other approach:
=SUM(SORTN(REGEXMATCH(B:B;E2)*C:C;3;0;ROW(B:B)*REGEXMATCH(B:B;E2);0))
Note the number 3 for the number of values you want from the bottom. and the reference to E2, which is "HH" as on your sample sheet.
use:
=QUERY(FILTER({IFNA(REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0);
"^([A-Za-z]{1,3})\d"))\SORT(C2:C; ROW(B2:B); 0)}; COUNTIFS(
REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0); "^([A-Za-z]{1,3})\d");
REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0); "^([A-Za-z]{1,3})\d");
ROW(H2:H43); "<="&ROW(H2:H43))<=3);
"select Col1,sum(Col2) group by Col1 label sum(Col2)''")
full explanation here

How to Get the Sum Total of a Category if Data is Split Between Multiple Adjacent Tables

I have attached a sample of the format the data I am working with is in. The actual data set has many more columns. So I am looking for a single formula that will get the totals for a category from the whole table. As you can see in the photo we have "Test 2" in columns B and D with values of 1 and 9 respectively. That is a total of 10. Is there a singular formula that would return 10? Thank you.
try:
=QUERY({FLATTEN(FILTER(B2:G10, MOD(COLUMN(B:G), 2)=0)),
FLATTEN(FILTER(B2:G10, MOD(COLUMN(B:G)-1, 2)=0))},
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label Col1'Name',sum(Col2)'Totals'")
for unknown number of columns try:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(
FILTER(B2:1000, MOD(COLUMN(B2:2), 2)=0)&"×"&
FILTER(B2:1000, MOD(COLUMN(B2:2)-1, 2)=0)), "×"),
"select Col1,sum(Col2)
where Col2 is not null
group by Col1
label Col1'Name',sum(Col2)'Totals'"))

ROUNDUP SUM values in a column in Google Sheets' query

I want to ROUNDUP the sum values in a column in my google sheets QUERY. I discovered adding format sum(Col2) '#' will do the trick as long as the sum is >.5. So how do I accomplish the same result if the value is <.5?
Here is my formula:
=QUERY(QUERY(Data!A3:D, "SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D format sum(B) '#'", 0),"OFFSET 1",0)
Currently, if the result is <.5, it will just display a blank space.
Here is a sample sheet
the only possible way would be:
=ARRAYFORMULA(IFERROR(ROUNDUP(
QUERY(QUERY(Data!A3:D,
"SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D", 0),"OFFSET 1",0)),
QUERY(QUERY(Data!A3:D,
"SELECT A,sum(B),C,D where A is not null GROUP BY A,C,D", 0),"OFFSET 1",0)))

Resources