Google sheets get empty cells next to each other - google-sheets

Link: https://docs.google.com/spreadsheets/d/1hCG6jjGSGWMn5kBkDfcoTJkZ2eCC5SRvHWMFTBp_6OE/edit?usp=sharing
I want to return "Yes" or "No" results in column N when there are empty cells next to each other in the range B:M
And column O counts the number of times there are empty cells next to each other.
Thank you.

use in O2:
=INDEX(LEN(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(IF(REGEXMATCH(TRIM(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(B2:M5="", "×", "¤")),,9^9)),
"¤")), "× ×"), 1, )),,9^9)), " ", )))
use in N2:
=INDEX(IF(O2:O=0, "No", "Yes"))

Related

How to use dynamic array formula to filter and format data

I am facing a problem related to the dynamic array.
I have data in the below format.
And I want to convert to this format.
Here is the sheet link.
I am using this formula to filter Fruits category.
={FILTER(A5:D11,B5:B11="Fruits");SUM( FILTER(D5:D11,B5:B11="Fruits"))}
But it gives this error
In ARRAY_LITERAL, an Array Literal was missing values for one or more rows
NOTE: Data should be pulled dynamically from the formula, as the data may change.
To build the result table without hard coding category names in the formula, use the recently introduced lambda functions, like this:
={
lambda(
data, categories, headers, totalsHeader, blankRow, selectPrice,
reduce(
headers, query(unique(categories), "where Col1 is not null", 0),
lambda(
resultTable, filterKey,
{
resultTable;
lambda(
filterData,
{
filterData;
{ totalsHeader, query(filterData, selectPrice, 0) };
blankRow
}
)(filter(data, categories = filterKey))
}
)
)
)(
B5:D,
B5:B,
B4:D4,
{ "", "Total:" },
{ "", "", "" },
"select sum(Col3) label sum(Col3) '' "
);
{ "", "Grand Total:", sum(D5:D) }
}
See { array expressions }, filter(), query(), reduce() and lambda().
The formula will repeat each category name on several rows. If they get in the way, you can hide them from view by using a conditional formatting custom formula rule.
I did some tests to add all the information in just one formula. It will change the format you want, but it will still divide all the information.
Here is the formula:
={"Fruits:","";QUERY(B5:D,"select C, D where B ='Fruits'");
{"Total:",SUMIF(B5:D,"Fruits",D5:D)};"","";
"Vegetables:","";QUERY(B5:D,"select C, D where B ='Vegetables'");
{"Total:",SUMIF(B5:D,"Vegetables",D5:D);"","";
"condiments:","";QUERY(B5:D,"select C, D where B ='condiments'");
{"Total:",SUMIF(B5:D,"condiments",D5:D)};"","";
"Grand Total:",SUM(D5:D)}}
Note:
I added : and the end of each category in the formula so they will look like Fruits: and the table will look like this:
The formula opens with { to open an array in Google Sheets, and you use , to separate columns to write a row of data, and ; to separate the rows to help you write a column of data. After that, you use } to close the array. For example:
{"1","2";"3","4"}
It will print:
So basically, I organize the data with arrays of the same amounts of columns. The first one with part
= { => To open the array.
"Fruits:",""; => This create a cell with "Fruits:" + an empty cell.
QUERY(B5:D,"select C, D where B ='Fruits'"); => which is
already on an array of 2 columns.
{"Total:",SUMIF(B5:D,"Fruits",D5:D)}; => Creates the "Total" cell + the sum
of values that has Fruits in column B.
"",""; => Which will create an empty row to separate the information
for the next set of arrays.
You do the same pattern for the other categories.
} => to end the initial array.
You can add a "Conditional formatting" that will change the text with : to bold automatically.
Reference:
QUERY function
SUMIF
ARRAYFORMULA
I suggest you read on: https://stackoverflow.com/a/58042211/5632629
the first part of your formula outputs a grid of 4×3 cells
the second part of your formula outputs a single cell
if you want to combine it properly use:
={FILTER(A5:D11, B5:B11="Fruits");
{"","","Totals",SUM(FILTER(D5:D11, B5:B11="Fruits"))}}
or:
={FILTER(B5:D11, B5:B11="Fruits");
{"","Totals",SUM(FILTER(D5:D11, B5:B11="Fruits"))}}

Array formula to join header values in a Google Sheet when row values equal "yes"

I saw this question but was not able to get it to work for me. Since it is already answered and from an year ago I felt it best to post a new question.
I have a sample sheet at: https://docs.google.com/spreadsheets/d/1EqNfTWcNFgkv2gdovnH7JpqU9V2HG5Vkoup8bhNqI7k/edit#gid=0
In F1 I want an array formula that will join the values of B1:E1 if B2:E = "yes".
Column G has the expected output.
This is what I came up with but it's giving error:
={
"output";
ARRAYFORMULA(
IF(
A2:A = "",
,
IF(
B2:E = "yes",
TEXTJOIN(", ", TRUE, B1:E1),
)
)
)
}
Try this out
=index(substitute(trim(transpose(query(transpose(if(B2:E<>"yes",,B1:E1)),,9^9)))," ",", "))
If the header contain spaces, use:
=index(substitute(substitute(trim(transpose(query(transpose(if(B2:E<>"yes",,substitute(B1:E1," ","❄️"))),,9^9)))," ",", "),"❄️"," "))
use:
=INDEX(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(B2:E="yes", B1:E1&",", )),,9^9))), ",$", ))

Google sheets - Extract numbers with their units of measurment

I want a function that can extract numbers with their units of measurment from a text.
For example in A2 i have:
This box weights 5kg and the other box weights 10 kg.
So i want a function that will return:
5kg 10kg
NOTE: I want the function to work with any unit of measurment, not just "kg".
I am a begginer in google sheets so it would be really helpful if you could provide me with a working function.
You can use this sample custom function that extracts words that starts with a number followed by a character/s.
/**
* #customfunction
*/
function EXTRACTMEASUREMENT(input) {
// match all words which starts with a number
var result = input.match(/\d+[a-zA-Z]+\S*/g)
// combine array into a string separated with spaces
result = result.join(' ');
// Remove special characters(except whitespace) in the string
result = result.replace(/[^\/a-zA-Z0-9\s]/g, '')
return result;
}
Output:
Limitations:
Measurements with spaces between the value and the unit cannot be detected. (See result in cell A5 when space exist in 10 kg.)
Regardless whether the character/s after the number is a valid unit or not, it will be extracted. (See result in cell A5 where 20yy is not a valid measurement unit)
If you want to exempt particular characters not to be removed, you can add them in the braces [^\/a-zA-Z0-9\s] (example / will not be removed).
Note:
This can be improved if you can list valid measurement units that should be supported.
Try
=arrayformula(substitute(transpose(query(flatten(split(
REGEXREPLACE(A1,"([0-9.,/]+[ ]{0,1}[a-z1-3/.\-""]+)","♣♦$1♣")
,"♣")),"select * where Col1 like '♦%' ")),"♦",""))
One more option:
=ArrayFormula(IF(LEN(A:A),
SPLIT(
REGEXREPLACE(
REGEXREPLACE(A:A,"("&
REGEXREPLACE(
REGEXREPLACE(
REGEXREPLACE(A:A,"(\d+[.,/]*\d*(?:\w+|\s\w+)[\""./\-\w+]*)",""),
"\s+\.","|\\."),
"\s+","|")
&")",""),
"(\d)\s","$1")
," ",,1)
,))
try:
=INDEX(SPLIT(FLATTEN(QUERY(TRANSPOSE(IFERROR(SUBSTITUTE(
REGEXEXTRACT(SPLIT(REGEXREPLACE(A1:A, "(\d+.\d+|\d+)", "×$1"), "×"),
TEXTJOIN("|", 1, {"\d+.\d+ ","\d+.\d+","\d+ ","\d+"}&
SORT({"nm";"mm";"cm";"dm";"km";"m";"t";"kg";"dg";"g";"l";"ml";"dl"},
LEN({"nm";"mm";"cm";"dm";"km";"m";"t";"kg";"dg";"g";"l";"ml";"dl"}), 0))),
" ", ))),,9^9)), " "))
update:
all in one cell:
=INDEX(TRIM(FLATTEN(QUERY(TRANSPOSE(IFERROR(SUBSTITUTE(
REGEXEXTRACT(SPLIT(REGEXREPLACE(A1:A, "(\d+.\d+|\d+)", "×$1"), "×"),
TEXTJOIN("|", 1, {"\d+.\d+ ","\d+.\d+","\d+ ","\d+"}&
SORT({"nm";"mm";"cm";"dm";"km";"m";"t";"kg";"dg";"g";"l";"ml";"dl"},
LEN({"nm";"mm";"cm";"dm";"km";"m";"t";"kg";"dg";"g";"l";"ml";"dl"}), 0))),
" ", ))),,9^9))))

Google Sheets SUMIF Text Formula

Ok so, I will arleady say that im not that good with excel and even worse on google sheets.
I would like to know if there is a formula that checks for the name of someone and then sums the points said person got to his total. Thank you very much!
https://docs.google.com/spreadsheets/d/1D4M8Dlao8yFHJulNDff-i2jZJeVGGY_gejbAfzWdhFo/edit?usp=sharing is the link if you want to check it out.
I assume you want Punti tot. (R:R) column to have the sum of all TA Brawl (column C:C), Notte (L:L) and 50 Shades (H:H; in this case any of the two players should be checked, right?) for every player.
You can use put this in R2 (do not forget to remove everything below R2):
={
"Punti tot.";
ARRAYFORMULA(
IF(
P3:P = ""; ;
SUMIF(A3:A; P3:P; C3:C)
+ SUMIF(E3:E; P3:P; H3:H)
+ SUMIF(F3:F; P3:P; H3:H)
+ SUMIF(J3:J; P3:P; L3:L)
)
)
}
Update: here is another solution using QUERY which is also sorts players by total points:
=QUERY(
{
FILTER({A3:A\ C3:C}; A3:A <> "");
FILTER({E3:E\ H3:H}; E3:E <> "");
FILTER({F3:F\ H3:H}; F3:F <> "");
FILTER({J3:J\ L3:L}; J3:J <> "")
};
"
select Col1, SUM(Col2)
group by Col1
order by SUM(Col2) desc,
Col1
label Col1 'Player',
SUM(Col2) 'Punti tot.'
";
-1
)
And you might want to use this in O2 for ranking:
={
"Posizioni Finali";
ARRAYFORMULA(
RANK(
FILTER(Q3:Q; Q3:Q <> "");
FILTER(Q3:Q; Q3:Q <> "")
)
)
}
This way same amount of points gives players the same place. Otherwise hysen would get 9th place and Imurshh would be 10th just because h goes before i.

how to compare rows based on reference from another column?

how can I check numbers in a range A1:A20 if they are not same and put that in cell E1
and then check range B1:B20 and if any row in B column consists of number "1" then from range A1:A20 check only rows where rows are set "1" in column B and check them if they are not same and put that into E2
it should look like this:
so far I have only this piece =IF(COUNTIF($A$1<>$A$2);"OK";)"NOT OK") but stacking more <>$A$3<>$A$4<>$A$5... brokes it
This is an easy way to do it.
Can you add three new columns (hide them afterwards if you'd like)? If so insert two new columns after column B.
In C1 put
=COUNTIF($A$1:$A$20, A1)
Drag that formula down until C20.
Now in H1, put:
=IF(AVERAGE(C1:C20)=1, "OK", "NOT OK")
Now for the second part...
In D1 put:
=IF(B1=1, A1, "")
In E1 put:
=IF(B1 = 1, COUNTIF($D$1:$D$20, D1), "")
And drag it down.
In H2, put:
=IF(AVERAGE(E1:E20)=1, "OK", "NOT OK")
With one helping Column:
In C1 Put
=IF(B1="";"";COUNTIFS($A$1:A1;A1;$B$1:B1;1))
and drag it down
In E1 Put
=IF(COUNTA(A1:A20)-SUMPRODUCT(1/COUNTIF(A1:A20;A1:A20))=0;"OK";"NOT OK")
In E2 Put
=IF(MAX(C1:C20)>1;"NOT OK";"OK")
An alternate solution is to use array formula:
Checking for unique entries in the full range
In G1 put
= SUM( COUNTIF( $A$1:$A$20, $A$1:$A$20 ) )
and turn this into an array formula by holding down CTRL & SHIFT when pressing ENTER.
Then in G2 put
= COUNT( $A$1:$A$20 )
And in E1 put
= IF( G1 = G2, "OK", "Not OK" )
This solves checking for unique entries across the full selection.
Checking for unique entries across a selection
Similar approach, but using a SUMPRODUCT.
In H1 put
= SUMPRODUCT( COUNTIFS( $A$1:$A$20, $A$1:$A$20, $B$1:$B$20, ">0" ), $B$1:$B$20 )
and turn it into an array formula (CTRL + SHIFT + ENTER)
In H2 put
= SUM( $B$1:$B$20)
And in E2 put
= IF( H1 = H2, "OK", "Not OK" )
I think you could also have this check full columns (rather than a defined range) by change (for instance) $A$1:$A$20 to $A:$A but haven't checked.

Resources