Counting unique values when other criteria must also be met - google-sheets

I'm having difficultly with Google Sheets counting unique rows, where other criteria in the formula must also be met.
I've created a simple Google Sheet to highlight the problem I need solving.
https://docs.google.com/spreadsheets/d/1P0sHIUN12Wpbr6vKJAwsPluj-T2H-NrPpQ1_WWV7lvI/edit?usp=sharing
I need the formula in cell C5 to only count unique values in row G, where the criteria is met in rows F & H (the SP is “DG” and the likelihood is “Booked”). I cannot work out how to make this only count unique values. The formula I currently have only counts any cells that are not blank in row G, it does not look for unique values but needs to.
The working formula should give the following answers:
C3 = <> C5 should equal 3
C3 = 1 C5 should equal 1
C3 = 2 C5 should equal 2
C3 = 3 C5 should equal 1
Please can someone help?
EDIT
The formulas I've already tried won't make sense with the example in the link but to show what I have attempted
=COUNTIF(UNIQUE(QUERY(AA:AM,"Select AC where AA = 'DG' and AL = 'Booked' and AM = '" & I2 & "'")),"<>")
It returned a 1 regardless of how many it should have returned.

=COUNTUNIQUE(QUERY(F2:I21,"Select G where F='DG' and H='Booked' "&IF(ISBLANK(C3),,"and I="&C3&"")))
QUERY to get G column subject to conditions
COUNTUNIQUE to count unique G Rows

Related

Return 1,0 after looking through multiple scenarios if any are true

I need column J to look at multiple different scenarios and return 1,0 if any are true.
In J1 (and continuing down column J)
if B1 is a number and
B2 and B3 are blank and
the sum of G1:G3 is 2 or more
or
if B1 is a number and B2 is a number or if B2 is "-" and B3 is a number
then return 1
However, if in the range of H1:H3 there is a FALSE,
then an additional row must be added to the sum of G1:G3.
If B1 is "-" then J1 is empty
EXAMPLES:
B1 is a number, B3 is also a number, so J1 should read 1
B11 Is a number. B12:B13 are "-". So then we look to the sum of G11:G13. That equals 2, so J11 should read 1.
B23 is a number, and B24:B25 are "-". So then we look to the sum of G23:G25. However H25 is False, so now we look to the sum of G23:G26. If H24 is false too, then we would look to the sum of G23:G27.
One goal is to always add three applicable values from G, looking at H to determine applicable values.
I could split up these formulas into multiple columns if needed.
SAMPLE SHEET
I worked out this formula
=if(B1="-","",if(or(IF(AND(ISNUMBER(B1),SUM(G1:G3)>=2,B2="-",B3="-"),1),if(and(isnumber(B1),or(isnumber(B2),isnumber(B3))),1)),1))
But have no idea how to add the stipulation for column H when a FALSE is present.

Google Sheets- Countif Formula Count Cells specific text Multiple Criteria

I currently have a google sheet in which I count values in Column L against a reference sheet 'Ref' and then against a status Column W
IF(AND(COUNTIF(Ref!$A$1:$A$100,L2),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
However the values have now changed in Column L. Instead of defined values in each cell they will be a string of values in each cell, the permutations will be too great to enter into my reference sheet.
How do I still count the values in column L to correctly return a 'Y' or 'N'
I have tried
=IF(AND(COUNTIF(L2,{"*LEE*","*LON*","*LAM*"}),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
=IF(AND(COUNTIF(Ref!$A$1:$A$100,"*"&L2&"*"),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
=IF(AND(COUNTIF(L2,{"*LEE*","*LON*","*LAM*"}),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
The values I which need to count will feature one of the following phrases 'LEE', 'LON','LAM'.
The new values that are entered into column L will look like the following
<Area1: Y - LEE>,<Area2: Y - MIL>
<Area3: WF>,<Area4: Y - MUN>
<Area1: YY - MUN>,<Area2: YY - LON>,<Area3: YY-LAM>
So I need to be able to search within the cell for 1 of the 3 phrases.
Any help greatly appreciated
Thanks
I have a solution that might work, using arrayformula() in a single cell.
If I've understood correctly, it looks like you're checking Col L to see if cells contain LEE LON or LAM. You're also checking to see that they appear in Ref!$A$1:$A$100.
On your sheet that contains col F and Col W (Status), try this in row 1 (I've used AB1):
=arrayformula({"Check";if(if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)<>"",if(REGEXMATCH(join(" ",Ref!A2:A),if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)),if(regexmatch(W2:W,"Cancelled|Postponed|Dropped"),"N","Y"),),)})
To show the working, I've got three helper columns, AD, AE and AF:
AD1 gets LAM LEE or LON from col L:
=arrayformula({"LAM|LEE|LON entry";if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)})
AE1 checks the values in col AD to see if they appear in Ref!A2:A:
=arrayformula({"LAM|LEE|LON match";if(AD2:AD<>"",REGEXMATCH(join(" ",Ref!A2:A),AD2:AD),)})
AF1 checks if the value in col AE is true, then the status from col W:
=arrayformula({"Check";if(AE2:AE=true,if(regexmatch(W2:W,"Cancelled|Postponed|Dropped"),"N","Y"),)})
The 3 helper columns are combined in AB1.

Filter and sort results, ignoring rows with no data, with 2, 3 or 4 conditions

I have a large database from Y to BF.
Columns Y to AB are the categories of all the rest.
I want to apply a filter function that will only filter results with rows with data (ignore all other columns/rows blank).
Conditions for Filter are in B2 ; D2 ; F2 ; H2 .
I also want to be able to Sort results according to O2 and in a Ascending or Descending order according to Q2.
In A6 I have a formula that only shows titles with corresponding data, BUT it doesn't respect possible 4 conditions, only one, the first in B2
=FILTER( AD2:AJ2,INDEX(AD2:AJ,MATCH( B2,Y3:Y,0 ),)<>"" )
In A7 i have a formula (not working) that only fills filtered results according with B2 + D2 + F2 + H2 BUT doesn't show only rows with data, it shows all columns
=IFERROR(SORT(FILTER(AD3:BF,
IF(B2="",ROW(Y3:Y),Y3:Y=B2)*
IF(D2="",ROW(Z3:Z),Z3:Z=D2)*
IF(F2="",ROW(AA3:AA),AA3:AA=F2)*
IF(H2="",ROW(AB3:AB),AB3:AB=H2)),
IF(O2="",1,MATCH(O2,A6:R6,0)),
IF(Q2="Asc",1,0)),"Sem Navios")
My difficulty is that my current formulas respect the 4 conditions (even in case some one is blank) BUT does not filter columns only with data, it spills all columns and that is very confusing.
Can someone help me getting to filter data according to 4 conditions (even in case some one is blank), being able to sort and only shows rows with data?
Thanks.
Example sheet here https://docs.google.com/spreadsheets/d/11B-4rjP9_8brvF0A3yVJlIoiyXWqxM91qWtKRSD8tLI/edit?usp=sharing
Feel free to edit.
I have a "desired results" tab, with no formulas, just showing what I pretend.

Count cell in a row if is not empty in a none consecutive range of four columns google sheets

I'm looking get the count of each row where the cells are not empty in a none sequential range (A3:A;C3:C;E3:E;G3:G) .
Say if A3 is not empty and C3, E3, G3 is empty than the result would be 1
Say if A3 and C3 is not empty and E3, G3 is empty than the result would be 2
Say if A3 , C3 and E3 is not empty and G3 is empty than the result would be 3
I like that done for the entire range.
BASICLY COUNT EACH CELL WITH ANY VALUE ON EACH ROW AND RETURN THE RESULTS OF THAT ROW.
I need the same results as =countA(A3:G) for each row inoring columns(B,D,F) in some type of an arrayformula.
Thanks for the help in advance
Wilson
link to the sheet:
LINK TO SHEET
See if this helps
=ArrayFormula(if(len(A3:A); MMULT(N({A3:A\C3:C\ E3:E\ G3:G}<>""); {1; 1; 1; 1});))
Or, in a more general approach (filtering out the odd columns)
=ARRAYFORMULA(IF(LEN(A3:A); MMULT(N(A3:G<>""); N(TRANSPOSE(ISODD(COLUMN(A3:G3)))));))
Try below formula :
=Arrayformula(IF(A3:A<>"",1,0)+IF(C3:C<>"",1,0)+IF(E3:E<>"",1,0)+IF(G3:G<>"",1,0))

ARRAYFORMULA - How to reference previous column

Lets say I have a row where's there's a % increase based on the value in the previous Column so
A1 = 1
B1 = A1*1.1
C1 = B1*1.1
....
G1 = F1*1.1
Is there an ARRAYFORMULA that can be entered into B1 that can do this?
#pnuts's answer can be improved upon and made to work by actually deleting part of his formula:
=transpose(ArrayFormula(1.1^row(1:10)*A$1))

Resources