How to find next available date inline - google-sheets

I have this demo sheet
https://docs.google.com/spreadsheets/d/1iexvfvQVHUc8BooAxpDg8awf6CDpv80b6Z_etBNPc0M/edit?usp=sharing
What I need is an arrayformula is to find inline the next available date from Col "C" and Col "D" dates, and apply colors depending on it
Also, want to have a "Past" in the dates already past
I have in Col F my expected result, cuz is hard to explain exactly what I need
Any help please.

=ARRAYFORMULA(QUERY({IFERROR(QUERY(IF(LEN(C2:C),
IF((C2:C<TODAY())*(D2:D<TODAY()), "Past",
IF((C2:C<TODAY())*(D2:D>TODAY()), "On Going now", )), ),
"where Col1='Past' or Col1='On Going now'"),"");
QUERY(IF(LEN(C2:C),
IF((C2:C>TODAY())*(D2:D>TODAY()), "Next Available", ), ),
"where Col1='Next Available' limit 1")},
"where Col1 is not null"))

Related

Count the number of instances in a Google Sheets array where a formatted input meets a specified logical condition

I want to create a heatmap in Google Sheets that displays the most active hours for team members using conditional formatting. The first page has columns for each weekday and rows for each team member, with cells containing their start and end times.
The second page has columns for each weekday and rows for each hour in a 24-hour cycle. I'm having trouble getting the number of people available at a given hour from the data on the first page. And it's hard for me to find the problem's source, since Sheets don't offer good solutions for debugging or doesn't give me an error.
Here's a link to an example of what i want the output to look like.
I've tried 3 different solutions. Using =ARRAYFORMULA, =COUNTIF and =COUNTIFS
The logical comparisons work nicely, it's when I try to count them where I run into a problem.
Here's what I tried to do with arrayformula:
=ARRAYFORMULA(
SUM(
VALUE(
IF(
OR(
ISBLANK(Page1!$B$2:$B$4),
ISBLANK(Page1!$C$2:$C$4)
),
0,
IF(
OR(
MOD($A2,1)>=TIME(LEFT(Page1!$B$2:$B$4,FIND(":",Page1!$B$2:$B$4)-1),0,0),
MOD($A2,1)<TIME(LEFT(Page1!$C$2:$C$4,FIND(":",Page1!$C$2:$C$4)-1),0,0)
),
1,
0
)
)
)
)
)
And here's what I tried to do with countif:
=COUNTIF(
IF
(
AND
(
TIMEVALUE(Page2!$A2) >= TIME(LEFT(Page1!$B$2:$B$4,FIND(":",Page1!$B$2:$B$4)-1),0,0),
TIMEVALUE(Page2!$A2) <= TIME(LEFT(Page1!$C$2:$C$4,FIND(":",Page1!$C$2:$C$4)-1),0,0)
),
"TRUE",
"FALSE"
),
"TRUE"
)
One suggestion was to use =COUNTIFS(Page1!B2:B4, "<="&A2, Page1!C2:C4, ">="&A2) but this also always returns 0.
try:
=INDEX(IFNA(VLOOKUP(TO_TEXT(A2:A), TEXT(QUERY(SPLIT(FLATTEN(SEQUENCE(7, 1)&"×"&
SPLIT(QUERY(FLATTEN(QUERY(BYCOL(Page1!B2:O4, LAMBDA(y, (BYROW(y, LAMBDA(x,
TEXTJOIN(" ", 1, IFERROR(SEQUENCE(1, HOUR(OFFSET(x,,1)-x), 0)/24+x))))))),,9^9)),
"skipping 2", ), " ")), "×"), "select Col2,count(Col2) group by Col2 pivot Col1", ),
{"h:mm", "#", "#", "#", "#", "#", "#", "#"}), SEQUENCE(1, 7)+1, 0))+0)
input:

I'm scraping from Finviz, how do I correct the 1.17B result to standard form? (Google Sheets)

So I have the input to scrape on Google Sheets as follows:
=VALUE(SUBSTITUTE( index(IMPORTHTML("http://finviz.com/quote.ashx?t="&$C7,"table", 9),3,2),"*",""))
The C7 box contains the ticker SBSW and the result shows 1.17B, however because there is the B, it is showing #VALUE!
I'd like to know how to convert the 1.17B to the Standard form of the number. How can I adapt my current code to accomplish that?
Edit: the same issue occurs with '-' (hyphen) results.
Use regexextract() and regexreplace(), like this:
=value(
regexextract(
regexreplace(
regexreplace(
query(
importhtml("http://finviz.com/quote.ashx?t=" & C7, "table", 9),
"select Col2 where Col1 = 'Income' ", 0
),
"B", "e9"
),
"M", "e6"
),
"[-\d.e]+"
)
)
To learn the exact regular expression syntax used by Google Sheets, see RE2.

Get the last value of a column when another has a specific value

In this great community I always like to learn with what I am discovering, that is why I would like to know if this solution that I have found can be done in a better way.
I have two columns where I am introducing values and I get a value from a column according to the condition of the first one.
I do this with the following google sheets formula:
=INDEX(filter(Blockchains!F$2:F,Blockchains!E$2:E=VALUEA),ROWS(filter(Blockchains!F$2:F,Blockchains!E$2:E=VALUEA)),1)
Is there a way to make it better?
try:
=INDEX(QUERY(SORT(E:F, ROW(E:E), ), "where Col2 = 'VALUEA'", ), 1, 1)
better safe than sorry:
=INDEX(QUERY(SORT(E:F, ROW(E:E), )&"", "where Col2 = 'VALUEA'", ), 1, 1)

Google Sheets return value based on multiple conditions

I have a google sheet that looks like this
Empty sheet
In the same sheet, I have this source data:
Source data
The name column is the exact same names that are arranged horizontally in the sheet
The status column is a text
My goal is to add either an "X" or "O" in the cells under each name and next to the appropriate date column based on the status of each person on a specific day.
If status = "On site" then put "X", if status is "Off site" then put "O"
The output should look something like this:
Goal
So 3 things should match: name, status, and date
I tried using IF() functions with AND() but it's not giving me the desired output.
I tried the following:
=IF(AND(T15="Person 1", U15="On site", V15=A2), "X", "O")
V15 is the cell containing the source date and A2 is the cell containing the destination date
Why is this not working? What am I doing wrong? any help is greatly appreciated!
try in C2:
=INDEX(IFNA(SUBSTITUTE(SUBSTITUTE(VLOOKUP(A2:A,
QUERY({T15:V22; SPLIT(FLATTEN(C1:M1)&"×!×1", "×")},
"select Col3,max(Col2) where Col2 is not null group by Col3 pivot Col1"),
MATCH(C1:M1, TRANSPOSE(SORT(FLATTEN(C1:M1))), 0)+1, 0),
"On site", "X"), "Off site", "O")))
update
optimized formula:
=INDEX(IFNA(IF(A2:A="",,SUBSTITUTE(SUBSTITUTE(VLOOKUP(TO_TEXT(A2:A),QUERY({QUERY(TEXT(
IMPORTRANGE("1IANXcVXKRMj591vs_jLkHAQp-ZCoZFpbf7xOSm2srJA", "Form Responses 1!A2:C"),
{"m/d/yyyy", "#", "#"}), "where Col2 <> '0'");
SPLIT("!×"&FLATTEN(C1:M1)&"×!", "×")},
"select Col1,max(Col3) where Col2 is not null group by Col1 pivot Col2"),
MATCH(C1:M1, TRANSPOSE(SORT(FLATTEN(C1:M1))), )+1, ),
"Working alone", "X"), "Not working alone/Not working", "O"))))

Combine Multiple cells with same value as one cell for average in Google Sheets

I'm using large data sets to create min/max and averages.
Most specifically, when finding the average for performance reasons. I have some values that are the same up to 50 times. I don't want 50 columns or 50 rows of the same value. Is it possible to combine one cell as 50 of the same value to use in an average?
I've looked on Google, and other websites and I haven't found anything that is relative to what I'm looking for. I'm not looking reformat all the data unless its the only way.
For instance:
959, 10000 (x50), 12000 (x9), 12100, 15500
I did multiple values already but 4-5 data sets have up to 55 of the same data values.
I feel the min and max will change be not be difficult because multiple values are omitted.
Is there a value I can give to that single cell for google sheets to recongize it as 50 of that value?
Any help could be appreciated?
Link example of a data sheet that is considerably smaller than mine, want to use 1 cell for 14k etc. if possible.
https://docs.google.com/spreadsheets/d/1R9qwnrfqzjMn6QQURDPZni8FE-H45OWB3Tvog8VRIfE/edit?usp=sharing
try average of unique set:
=AVERAGE(UNIQUE(A:A))
UPDATE:
=ARRAYFORMULA(SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(C:D), "♦"&C:D&" 1", IF((C:D<>"")*
(NOT(ISNUMBER(C:D))), "♦"&REGEXREPLACE(C:D, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col1*Col2 label Col1*Col2 ''", 0))/
SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(C:D), "♦"&C:D&" 1", IF((C:D<>"")*
(NOT(ISNUMBER(C:D))), "♦"&REGEXREPLACE(C:D, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col2", 0)))
MAX/MIN
=ARRAYFORMULA(MAX(QUERY(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
TRANSPOSE(C:D),,99^99)),,99^99), " ")), "where not Col1 contains '-'", 0)))

Resources