Google Sheet Countifs with Multiple Criteria - google-sheets

I'm planning to create a dynamic cell which can count total items or only certain items.
I used the following formula to get the total items. But this formula doesn't work when I filter by item.
=ARRAYFORMULA(SUM(COUNTIFS(A:A;{“D1”;{“APPLE”;”ORANGE”;”POMEGRANATES”}};B:B;”1/6/2022″)))
*D1 = Dropdown for Apple/Orange/Pineapple/Pomegranates
The result I expect is:
If I select Apple then the only value that appears is Apple (4/10).
Apple = 4
Orange = 3
Pineapple = 1
Pomegranates = 2
And
If I don’t select Apple then the values that appear are all values (10/10)
All Fruit = 10
I would be very grateful if you could tell me where the error is and provide a solution.
Demo Sheets

Try this out
=QUERY(
{A:B};
"select Count(Col1)
where
Col1 matches '"&IF(ISBLANK(D1);".*";D1)&"' and
Col2 = date '"&TEXT(DATE(2022;6;1);"yyyy-mm-dd")&"'
label Count(Col1) ''")
If D1 is blank, it'll return everything (.* / the wildcard) -- otherwise it'll pull the word in D1.
If you wanted to use a cell reference for the date, you can replace DATE(2022;6;1) with that cell reference.

Try
=sumproduct(regexmatch(A:A; IF(LEN(D1); D1; "Apple|Orange|Pomegranates|Pineapple")); B:B= date(2022; 6; 1))
and see if that works?
Note that regexmatch is case-sensitive.

Related

Google Sheets - Using a sum formula and multiplying that sum depending on the status of checkboxes

I'm just starting and trying to learn about google sheets and I've got a much more involved sheet than what I'm showing here, but essentially I have ten check boxes and those boxes are each given a unique value when checked. When not checked they are all 0.
In this image I have 10 boxes in column A, with their assigned ON values in column B. Column C1 has the =SUM formula.
What I'm trying to figure out is how to multiply the summed number if boxes 9 OR 10 are selected. So box 9 and 10 would still contribute their value for the sum function but then would also have a multiple value that is triggered for the summed total.
Thanks in advance for any help!!
edit: sorry, I think I've caused some confusion. The values in the B column are just a visual representation of the value of the assigned value of the check boxes themselves, they aren't actually necessary to be used, but I'll see if I can use any of the answers listed to logic my way through it! thanks!
use:
=SUMPRODUCT(SUMIF(A1:A10, TRUE, B1:B10)*IF(A9=TRUE, B9, 1)*IF(A10=TRUE, B10, 1))
Try this
=ArrayFormula(IFERROR(SUM(QUERY(VLOOKUP(
QUERY(IF(A1:A<>TRUE,,ROW(A1:A)), "Select * Where Col1 is not null",0),
QUERY({ROW(A1:A),B1:B}, "Select * Where Col1 is not null") ,2,0), " Select * where Col1 is not null "))*
PRODUCT(QUERY(VLOOKUP(QUERY(IF(A1:A<>TRUE,,ROW(A1:A)), "Select * Where Col1 is not null",0),
QUERY({ROW(A1:A),B1:B}, "Select * Where Col1 is not null") ,2,0), " Select * where Col1 is not null ")),""))
Test all checkboxes

Query and Importrange to get the last value of the selected row of spreadsheet | Google Sheets

Right now I am using this query to search for a row based on its Column 1 value. Then it takes the value from the last column. I need a way for it to automatically find the last column in the row since some of the rows have more columns than others.
This is what I had before, which I had manually specified the last column with a value:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select Col10 where Col1 = '5531001'",1)
I have tried using LOOKUP with ARRAYFORMULA I couldn't get it to work:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select (LOOKUP(1, ARRAYFORMULA(1/[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']<>"")[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']))",1)
Any ideas for a simpler way to do this?
Since no example is presented, I tested the formulas given but no source data is fetched.
so i created a a minimal, reproducible example
Example is the data on the left
Use this formula to get the last non empty columns values.
=ArrayFormula(IFERROR( REGEXEXTRACT( TRIM(TRANSPOSE(QUERY(TRANSPOSE(C3:E),,ROW(C3:E)))), "[^\s]+$")))

Google Sheet | Excel | Array Formula + CountIf + Partial Text Problem

I'm pretty new with ArrayFormula, have been trying but sometime the formula works, sometimes does not. What I'm trying to do is the combination of ArrayFormula, Countif for searching partial text.
As shown in the worksheet below, there are 10 subjects (column A), each subject has at least one of 4 samples (A,B,C,D) summarized as a string (column B). What I'm trying to do is to find which subject has sample A or B or C or D.
I have tried single formula for each sample, eg cell D3
=IF(COUNTIF($B3,"*"&$D$2&"*")>0,$A3,"")
it returns the correct results. However, when I try arrayformula in cell I3,
=arrayformula(IF(COUNTIF($B3:B,"*"&$D$2&"*")>0,$A3:A,""))
The answers are weird. For example: Subjects (Gamma, Zeta, Eta, Theta) who don't have the sample "A" are shown to have sample "A". And this applies to sample B,C,D too
Not sure what went wrong in here. Here is the link to the worksheet
I wouldn't use Countifs or an array formula. Use filter instead. Put this formula in cell i3.
=Filter(if(REGEXMATCH(B3:B,$D$2),A3:A,""),B3:B<>"")
try:
=INDEX(QUERY(IFERROR(TRIM(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B3:B, ","))="",,
SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"))
or use in row 2 if you want to sort it as in your example:
=INDEX(IFNA(VLOOKUP(A2:A, QUERY(IFERROR(TRIM(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B3:B, ","))="",,SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select Col2,max(Col2) where Col2 is not null group by Col2
pivot Col1 label Col2'Subjects'"), {2,3,4,5}, 0)))
You can accomplish all four columns of results with a single formula.
Delete all formulas from I3:L3.
Place the following formula into I3:
=ArrayFormula(IF(REGEXMATCH(B3:B,I2:L2),A3:A,))
In plain speech, this read "If anything in B3:B matches a value found in I2:L2, return A3:A in the matching columns(s) at the matching row(s); if not, return null."

How to use google sheets to transpose a set of cells that correspond to a specific input date?

I am trying to set up a calendar-type to-do list on google sheets. I would like to be able to take a date from a certain cell on sheet 1, and use it to match up to a to-do list from another sheet (sheet 2) that corresponds with the same date that's at the top of the column, then transpose the data from sheet 2 onto sheet 1. Should I try to use a transpose function? Hlookup?
query function would work well:
=query(Sheet1!A:D,"select * where A = date '"&text(G1,"yyyy-mm-dd")&"' order by B,C,D ",1)
For ease, I've shown it on the same sheet.
More about query:
https://developers.google.com/chart/interactive/docs/querylanguage#language-clauses
Some alternatives:
=query(transpose(Sheet1!1:4),"select * where Col1 = date '"&text(A7,"yyyy-mm-dd")&"' order by Col2 ",1)
=transpose(query(transpose(Sheet1!1:4),"select * where Col1 = date '"&text(A7,"yyyy-mm-dd")&"' order by Col2 ",1))

use Google Sheets QUERY to sum column where = x on a different sheet

I have a spreadsheet with 2 sheets in it,
I want to summarize the daily results by date.
I'm trying to use the query sum function to summarize everything since I wasn't able to do it with arrayformula.
but I'm not able to do it with a query as well.
I don't want to just copy-paste the sum function from each row to the next I want to just type the date I need in column A and get all the results in the different columns.
https://docs.google.com/spreadsheets/d/1ZsKXw32ycO_5KGD2I-Ug_GmqSIB_Z-D3Z1jlGd6fpTE/edit?usp=sharing
link to sheets.
getting the data from the database sheet.
I want to display the data-oriented by date and sumed.
for just 1 row you can simply do this and then drag down:
=ARRAYFORMULA(QUERY({TO_TEXT(DataBase!A:A), DataBase!B:E},
"select sum(Col5)
where Col1 = '"&TO_TEXT(A2)&"'
label sum(Col5)''", 0))
if array is needed then use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, QUERY(DataBase!A:E,
"select A,sum(E)
where A is not null
group by A
label sum(E)''", 0), 2, 0)))

Resources