Google sheets - Count duplicate text in a column with conditions - google-sheets

I have an spreadsheet like this:
product name
sold?
banana
FALSE
banana
TRUE
apple
TRUE
apple
FALSE
apple
FALSE
I'd like to add another column to display the number of unsold products. so the desired result would be something like this:
product name
sold?
available
banana
FALSE
1
banana
TRUE
1
apple
TRUE
2
apple
FALSE
2
apple
FALSE
2
Thanks.

You need COUNTIFS(). Try-
=COUNTIFS($A$2:$A,A2,$B$2:$B,FALSE)
For dynamic spill result, use MAP() function.
=MAP(A2:A6,LAMBDA(x,COUNTIFS(A:A,x,B:B,FALSE)))
To refer full column as input, use-
=MAP(TOCOL(A2:A,1),LAMBDA(x,COUNTIFS(A:A,x,B:B,FALSE)))

Related

How to use AND in Google sheets?

I am currently having hard time creating a formula for my sheet to record values when the following conditions will be met:
I want to give 15% discount from the original price if a Person purchased their ticket online (Online = TRUE), and only applicable for customers who is atleast 50 years old, kindly list the new calculated discounted price in the Discounted Price Column
I have tried creating a formula but I got formula parse error.
Formula used : =IF((B2=TRUE AND D2>50),(E2*0.85),E2)
This is my sample data in the sheet and the expected output on Discounted Price column. Any help will be appreciated.
Person
Online
Physical Store
Age
Original Price
Discounted Price
A
TRUE
FALSE
67
1000
850
B
TRUE
FALSE
16
1000
1000
C
FALSE
TRUE
24
1000
1000
D
TRUE
FALSE
52
1000
850
E
FALSE
TRUE
60
1000
1000
Your formula is almost correct except for the AND operator, the syntax for using AND is as follows: AND(logical_expression1, [logical_expression2, ...]).
I have replicated your data and fix the formula. Please see formula and desired output below
Formula:
=IF(AND(B2=TRUE,D2>50),(E2*0.85),E2)
Data and Output:
References:
https://support.google.com/docs/answer/7014145
https://support.google.com/docs/answer/3093301?hl=en
use:
=INDEX(IF(B2:B="",,IF((B2:B=TRUE)*(D2:D>50), (E2:E*0.85), E2:E))

Conditional formatting based on pairs of cells on different sheets

I'm attempting to apply conditional formatting if any two "paired" cells in two different ranges are both true.
The first range is on Sheet1, where the conditional formatting occurs. The second range is on Sheet2. However, the "pairing" is many to one, where the cells in a single Sheet1 column all map to one cell in Sheet2.
For example:
Sheet1
A (conditionally formatted column)
B
C
D
E
1
Value1 (formatting applies)
True
True
True
True
2
Value2
False
False
False
False
3
Value3
False
True
False
True
4
Value4 (formatting applies)
True
False
False
False
5
Value5 (formatting applies)
False
True
True
False
Sheet2
G
H
I
J
1
True
False
True
False
I'm currently using the following custom formula, and setting the conditional formatting range to A:A on Sheet1.
=OR(AND(B1, INDIRECT("Sheet2!G1")), AND(C1, INDIRECT("Sheet2!H1")), AND(D1, INDIRECT("Sheet2!I1")), AND(E1, INDIRECT("Sheet2!J1")))
The formula works for this example, but in reality I have 35 columns (and more to come). I'm looking for a more sustainable solution. Is there a way to use ranges in my example custom formula, instead of a series of AND conditions?
How about
=ArrayFormula(sum(B1:E1*indirect("sheet2!g1:j1")))
Or shorter
=SUMPRODUCT(B1:E1*indirect("sheet2!g1:j1"))
try:
=(((B1=INDIRECT("Sheet2!G1"))+(C1=INDIRECT("Sheet2!H1"))+(D1=INDIRECT("Sheet2!I1"))+(E1=INDIRECT("Sheet2!J1")))>1)*(A1<>"")
demo

Return filtered index in Google sheets

I would like to return all the rows in a column where a certain condition has been met.
So for example, assume this is spreadsheet 'one':
A B
Jay Yes
Tim No
Tom
Lane Yes
Luisa
I would like to return the names in spreadsheet one that have the value 'yes' in column B of spreadsheet one, leaving this as my desired out
A
Jay
Lane
I tried doing this:
=IF(One!B:B="Yes"One!A:A)
But this returns this
A
Jay
FALSE
FALSE
Lane
FALSE
In GS you can use:
=QUERY(A:B,"Select A where B = 'Yes'")
Or:
=FILTER(A:A,B:B="Yes")
The 2nd option would also work in Microsoft365.
Reference
QUERY function
FILTER function
=TEXT(FILTER(B!B:B,A:A=Yes cell)," ")
This should be easier. If you're referencing from a different "tab" add the tabs name.
=TEXT(FILTER(TabB!B:B,TabB!A:A=Yes cell)," ")
This is case sensitive from what I understand so it's worth noting in case of errors.

Count if rows in range have two criteria set

I cannot find a simple answer to this, sorry if this is super obvious.
I have a table:
A B
1 Fruit: Rotten?
2 Apple TRUE
3 Banana FALSE
4 Apple FALSE
5 Apple TRUE
Now I would like to have the formula for:
=COUNT(of rotten Apples in range A2:B5)
Any help would be appreciated.
This is pretty straight forward, you use COUNTIFS with multiple criteria
=COUNTIFS(A2:A5; "Apple"; B2:B5; TRUE)

CountIf with a multiplier

say I have the following table
1 apple
2 banana
2 apple
3 banana
With COUNTIF(B1:B4;"banana") I would get 2, but I'm searching for a formular that respects the mulitplier to get 5 as result. Is this possible?
Use sum if:
=SUMIF(B1:B4;"banana";A1:A4)
First range to search
Seccond the search item
Third The range for the sum

Resources