Weekday Values Script - google-apps-script

I have a Google Sheet that I am writing a script for. My newest section of a macro code is supposed to fill column F with a weekday numerical value based off of column B which has values of date and time (MM/DD/YY hh:mm:ss). Once I added the section to the end of the macro code, it comes back with the Error Code "Exception: AutoFill destination range must extend the source range in only one direction." The code will add the value, but it doesn't correctly correspond to most days.
spreadsheet.getCurrentCell().setFormula('=WEEKDAY(B2, 1)');
spreadsheet.getActiveRange().autoFill(spreadsheet.getRange('F:F'), SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
spreadsheet.getRange('F:F').activate();

Related

Is there a function that saves the last value inputted with query?

=IF(Summary!H2="October",QUERY(Summary!L2))
Hello,
I was wondering if it’s possible to record the last inputted value with a query function
As seen in the code above, when October is selected in the summary sheet, cell H2 - the cell with the function (above) outputs what is written in the summary sheet, cell L2
When I select a different month, the cell (where the code is written) changes to FALSE
Is there any way to make value_if_false equal the last value inputted into L2 when the selected month is changed?
If further proof is needed please let me know
Thank you,
Gabe
example
Don't know if this is what you mean, here I have created an example, where data is stored in the 'data' sheet, and the QUERY function is placed in the 'main' sheet.
B1, B2 is the condition inputs, I assume you want to sort your data by date, in that case, you will need a start day and an end day.
the QUERY formula will be something like this:
=QUERY({data!A:F},
" WHERE Col1 IS NOT NULL "
&" AND Col1 >= DATE '"&TEXT($B$1,"yyyy-mm-dd")&"' "
&" AND Col1 <= DATE '"&TEXT($B$2,"yyyy-mm-dd")&"' "
)
With this QUERY formula, the output data will change according to the date selected in B1 and B2.
Just make sure that the date column of your data page is formatted as date, otherwise google sheet QUERY will not be able to recognize the data as date.
link of the sample spreadsheet

Count the values from a variable column

I have a problem writing down a formula or a script in Google Sheet or Google App Script to find and count the values in a sheet where the number and references to the columns change.
I have a script that copy&paste the Sheet files for the staff shifts of every week from a Drive folder and merge them side by side (in horizontal).
In this sheet that contains all the shifts merged I want to count all the cells of the staff filtered only for handler and picker (column B, K, etc.) according to a specific date (row 3) for every hour.
Example: if today is 28/10/2020 find the right column with the same date in row 3 --> column E, count all the values from row 4 filtered by picker or handler for every hour (10 people at 05 AM).
Do you think that I can implement this with a formula (like a matrix, vlookup, etc.) or should it be written as a Script?
Thank you very much,
Marco
Please use the following
=COUNTA(QUERY({A3:I;J3:R},"select Col"&MATCH(A1,A3:I3)&"
where Col2 matches 'Technician|Picker' "))
Where B1 holds the date you wish to search for (28/10/2010)
Try the below formula. Replace date with your search date.
=COUNTA(INDEX(A4:R14,,MATCH(DATE(2020,10,28),A3:R3)))
This was earlier tagged as excel. This is how to "tackle" this in excel (office 365):
In a clear column use the following formula to get the unique hour-values that are in the column that equal today:
=UNIQUE(FILTER(INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0)),INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0))<>""))
In the column next to that type the following to get the result of the count of those unique values for that day:
=COUNTIF(INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0)), FILTER (I:I,I:I<>""))
Where I:I in FILTER (I:I,I:I<>"") needs to be changed into the column you put the first formula.

IMPORTRANGE() based on the date of another cell?

I am trying to use IMPORTRANGE() to import a sheet from another spreadsheet. I am currently using the following formula.
=IMPORTRANGE("URL", B1&"!A1:R25")
However, I am getting stuck with the sheet name. B1 is a cell that shows a date, consequently I want to import the sheet with that date as its name. Also, B1 determines that date based on a formula; here it is
=(Leftb(Summary!$A$2,2)&"-"&Midb(Summary!$A$2,3,2)&"-"&rightb(Summary!$A$2,2))+7
I believe since B1 contains a formula like this, something is getting messed up in the importrange(), either the formula or the format of the date.
Your current formula gets the value of the date, not the date that is displayed in the UI.
Try this formula:
=IMPORTRANGE("URL", TEXTJOIN("",TRUE,B1)&"!A1:R25")

I need to run a function when a cell changes value because of formula

Column D in my sheet contains a calculation of values in the row either by average, median, or mode based on user input. I need to run a function that will copy the formula's resulting value to a different spreadsheet each time the cell changes value. I have looked at onEdit() but don't understand it well. I won't be editing the cell directly. I don't want the cell to be copied if any cell in the row changes, only if the calculated value of that particular cell changes. Is this possible? Any help is appreciated greatly.
Column D contains:
=IFERROR(VLOOKUP(BU6,$A$106:$B$110,2,TRUE)," ")
BU6 contains: =IFERROR(ARRAYFORMULA(IF(C6="Average",BR6,IF(C6="Median",BS6,IF(C6="Mode",BT6))))," ")
A106:B110 contains:
When Column D changes from (let's say) A to C, I want to copy that letter into a different spreadsheet.

Max function not working on import range in google spreadsheet

I am new to google spreadsheet functions and trying to apply formula in following way:
I have an imported range as under in cell B2:
=importrange("1gRRBtq7KMAr5kY5AJBqFcLarkikqrAqr5CbeTc5mPzE/edit#gid","dstr!b2:b400")
This range contains different dates & I am trying to select last date with following function in B1:
=max(B2:B398)
But in place of showing date it is showing value.
Please help in solving this concern, for more detail you can go to following page:
https://docs.google.com/spreadsheets/d/1HTXf4VG2JupiP9UqCLRyAddYjhsom1leQOI9-DwfMaY/edit#gid=0
I selected cell B1 and clicked on the 123-button (in the menubar) and formatted that cell as date. See if that helps ?