Issue formatting date values in Google Sheet Query - google-apps-script

I created a shared shipment tracker with google sheets where updates are made in a master tab, then filtered into several regional tabs via query function to better visualize shipment status by region. Query used:
=IFERROR(Arrayformula(QUERY(Filter!A2:P&"","select * WHERE Col1 = 'BA'",0)),"No Data Yet")
I made one column (column P) a time stamp column that auto-populates the current date via a simple script every time an update is made in any given cell of the master tab.The script does its job formatting the date as desired, this is the section of the script where I add the date format:
setValue(new Date()).setNumberFormat("mm/dd/yyyy hh:mm:ss");
The problem is that when this data is pulled into any regional tab by the query function, the date format turns into a serial number. I've tried messing with the column formatting in all tabs, however the only way the regional tabs will show the date in my desired format (mm/dd/yyyy hh:mm:ss) is when I manually format the date values in the master tab as 'Plain Text'. Is there a way around this to display the desired date format in both the master and regional tabs without having to continually format the timestamp column in the master tab as plain text every time an update is made?

I'm not sure but how about this:
setValue(Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss");
Just use a string.

Related

Auto populate dates of the week Paginated reports

Good day
I am very very new two paginated reports so forgive me if this is a silly question
I have a report that displays values for Mondays to Fridays based on the date selected from a date picker.
So basically
You select a date (Example 24 Nov) and the following table is displayed based on values pulled from SQL.
Now my question is how do I display the dates of the weekdays too?
So if the date selected is Thursday 24 Nov, in the column headers under the week day names it should give the corresponding date i.e Monday-21/11/2022, Tuesday - 22/11/2022, etc.
Below is a little snippet of the data
So the date picker is based on the ReportingDate column. The rows of the matrix consist of Region and Country and the values are the sum of Monday-Friday.
Any guidance would be greatly appreciated.
Edit: The day names are not obtained via an expression in SSRS. They carry over from the column headers in the data set.
Assuming you have some expression to get the actual day name already, you can leave that bit as it is.
Now, double click the column header "cell"/textbox to get a cursor in there, then click at the end of the existing fields/expression.
Now just put a space in and then right-click and choose "Create Placeholder". The placeholder dialog will appear.
This placeholder acts almost like a separate textbox to you can put whatever you want in there, click the '[fc]' button next to the Value property and then set this to whatever you want, e.g. =Fields!ReportingDate.Value.
Now go to the "number" tab on the same dialog box and set the format to the required date format.
If you want to edit this later, just double click the cell again but this time right-click the placeholder and choose properties.
The other way of doing this would be to add another row to your header and set that to be the date instead but then you have to mess around removing borders etc., sometimes this can be easier if layout is an issue but you have a couple of options at least now.
I managed to figure it out with the help of the following post.
These are the steps I followed
Get the date of the first day of the current week (Sunday's date) using the formula explained in the link
DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))
Use DateAdd to add the corresponding number of days to get to a required weekday. That is for Monday add 1, Tuesday add 2,...
DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value)))
Format datetime to date and add new line to insert date below day name
="Monday" + Environment.NewLine + FormatDateTime(DateAdd("d",1,DateAdd("d",1- DatePart("w", CDate(Parameters!ReportingDate.Value)), CDate(Parameters!ReportingDate.Value))), DateFormat.ShortDate)

Weekday Values 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();

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")

How to automatically set the time-series value for the current date in Google Docs Script?

I have the following rows and columns. The value is coming from a simple API call. Is it possible to store that value for the current day and keep the previously stored value automatically? Right now, I simply copy paste the value for the day, but if I forget to update it, I might miss some data.
26/06/2019 0.01887913
27/06/2019
28/06/2019
29/06/2019
For example, for 27/06/2019, each time I open the doc, it would update the value if it is 27th, but then if I load the doc the next day, it will not be touching the 27th any more and will be updating the 28th.