GAS - How to get total hours for each employee, based on emp code from another workbook - google-sheets-api

Screen shot - Source to Destination
Screen shot for your reference
In Source WorkBook: I have a google sheet report with Employees' Daily Tracked Hours, with the location they have worked and their hourly Pay value. (emp code, emp name, hourly rate, location, etc.,)
In Destination WorkBook: I'm trying to consolidate each employee's Total pay hours based on emp. code in a single row and Add extra hours based on the location code from Source Workbook.
Dear Experts, Please help me to achieve this task with your valuable script/functions. :)
Destination WorkBook Link https://docs.google.com/spreadsheets/d/156EZ1rreEMr7_7uLxnpicGXFRpFB1ceVH_5H_hM2iAc/edit?usp=sharing
Source WorkBook Link https://docs.google.com/spreadsheets/d/1yN5b_K_G3OXZOE9HmeLtCE_-93e2aOOnuTuFpPAisxc/edit#gid=989746919

Related

How to bypass default parameter to include a range or better SQL?

EDITED (AGAIN): added tables and two screenshots (one of Google Sheets Chart and another showing mutliple issues in DS) to help demonstrate what I am seeing.
Short Version: I have created a parameter to help me score trending topics based on the date range filter. However, I want to be able to show a range of dates' worth of data, not just a specific date's worth of data. In theory, I could make the parameter a checklist with a huge range, but that doesn't seem efficient or sustainable down the road.
Disclaimer: I am about a week into SQL and Data Studio.
Long Version: We are tracking trends over time from a specific customer data set. I'd like to make it so that when a user adjusts the time range, various topics’ " score " depends on the end date. For instance, every time the topic "Recession" is brought up, it is given a score. That score is weighted based on when it was said. I was using 365 as the highest possible score so that anything over a year is null. So if "Recession" is referenced twice, once a week ago and once today, the avg score for recession is 361.5, but if a reference is made to the topic "Talent Management" twice today, then it would have a score of 365, and so forth across a growing list of 50+ topics pertaining to 50+ specific communities we are tracking the topics across.
Here is an example:
topics
groups
entry_date
recession
A
2022-11-24
talent mgt
A
2022-11-24
recession
B
2022-11-22
economy
A
2022-11-22
recession
C
2022-11-15
talent mgt
B
2022-11-8
This score would then affect the bubble size on a chart where the Y-axis is the count of unique groups referencing the topics, and an x-axis based on the range of average scores.
The goal is to be able to see which topics are the most common across groups, which ones are emerging trends, and which ones are dated trends by having a range slider. That way users (colleagues in other departments) can play with the date range "see" the bubbles moving in location and size.
example of static chart in google sheets
I could then also use the same data and fields to measure the percentage of topics being discussed across groups based on the weighted averages against a time range.
In Goolge Sheets I can do this with an xLookUp to a tab that has a column of 0-365 and then next to it a column of 365-0 (on a tab called 'scales') and then a cell on a sheet that you can put any date as the point in time, and it affects all the scores, tables, charts, etc. (I used. =xlookup((point_in_time - entry_date), 'scales'!A:A, 'scales'!B:B, "0")
In the data studios custom SQL I used:
SELECT
*
FROM
`qRaw_data'
where
DATE(_entry_dates_) between
parse_date('%Y%m%d', #DS_START_DATE) and
parse_date('%Y%m%d', #DS_END_DATE)
AND
#pit_date_diff = date_diff(
parse_date('%Y%m%d', #ds_end_date),
_entry_dates_,
day
)
Then I created a field that is time_score of:
avg((Pit_Date_Diff-365)*(-1))
I have been googling and youtubing like crazy and think I either have to come up with a way to override the #pit_date_diff default value OR I need to use a CASE WHEN in the custom query where each time the date_diff is 1 then 365, and so on, but when I try that I get all sorts of errors.
I would like below to include all topics averaged based on all entry dates, not just those that correlate with the inputted parameter field.
currently, I can only show specific entry dates due to the parameter
I appreciate any and all help. I am a week into using data studio and am going cross-eyed Googling and YouTubing things. There is likely a better logical path to accomplish all this. Hoping for a holiday miracle.
Thanks in advance.
It turns out this was much easier than I realized... I added an AS syntax to create a column and then created a field that created the same metrics that I had in the Google Sheets:
SELECT
*,
(date_diff(parse_date('%Y%m%d', #ds_end_date), _entry_dates_,day)) AS q_time_diff
FROM
`qRaw_data`
Then the score field is: (avg(q_time_diff)-365)*(-1)
In case that helps any others in the future... ¯\(ツ)/¯
Happy Holidays!

Email the Sales team their monthly Commission at an Order level

I am trying to find a way in SQL which would send email either as excel attachment or html to the Sales Teams on how much monthly commission did they earn on each order. Since it is commission, due to security reasons I cannot send a common file to everyone to look at each others commissions. Trying to put the scenario in a tabular form for a better understanding.
The first table gives you at an Order level who is getting paid how much. Which I already have in place
This table gives how much commission is paid individually and should email the same results to respective Sales Person based on Email address listed in 1st table

Issue in VBA excel

I have a list of Data that contains a list of machines with the following columns (good parts, bad parts, production date, end date, time/1pc = means time spent for one piece to make) these informations are used to calculate the 3 performance indicators in order to get the OEE for each machine.
I've created a user form that allows the user to enter the type of machine and the production date and by hiting ''OK'' the 3 indicators (availability, quality, performance) are calculated via a program in VBA excel. My Main objective is to create a dashboard that shows all these indicators plus the OEE for the type of machine selected by the user in a specific month I have created a worksheet for each machine containing in each column (the Month of the year the specific date, quality indicator, availability and performance and OEE) and by side there is a button that shows us a userform to select the week desired to calculate these indicators and there it goes my issue:
I'm trying to connect the userform before that calculate the indicators with this one that allows us to chose the week to fill the table for each machine with their indicators. How can I do that?

running totals when creating new excel workbooks and creating new worksheets when conditions are met

This is quite a long and complicated question, I will do my best to explain exactly what I need to do.
This applies to a flight department. Let's start with what I have, we use spreadsheets to track flight time, landings, and engine cycles. Currently we're using two spreadsheets, one is our "trip" sheet, and the other is our flight "log".
The trip sheet can be one to three worksheets long, it is used to track each flight flown during the trip. The trip could range from one flight (leg), up to 25 flights (legs), and could range from 1 day, to 21 days. Each DAY of the trip is it's own Log #, ie. if there are 3 flights on one day, they all share the same Log #. The trip #'s are not in order, one trip could be #672, the next #264543, the next #689. The creation date is the only thing that could be used to track the trip workbooks in order.
The flight log is the FAA required logbook for the aircraft. The Log #'s run in order, ie. 459, 460, 461. A flight log is required for each day that the aircraft flies. Some, but not all of the information from the trip sheet is required on the flight log. The most important thing is that the times, landing, and cycles calculate in order.
Now here is what I'm looking for. I'd like a spreadsheet that contains the three trip sheet worksheets as we have now, but when a flight (leg) is entered, it creates a 4th worksheet which would be the flight log. Each leg flown that day would have it's information transferred to that flight log. Now, when we fly on a NEW day, a 5th worksheet would be created for the new day's flight log. Times, landings, and cycle totals need to transfer over from the previous day's flight log, and the other information needed from the trip sheet just like the previous log. And so on, and so on, till the end of the TRIP.
Now here's the REAL tricky part, when we start a new TRIP, and create a new workbook for that trip, I need the totals from the previous trip to transfer to the new workbook, so a legal, running total of aircraft times can be kept.
So basically, what I want to do, is take two separate workbooks for each trip we use now, and cram them into one, but each time a new trip workbook is created I need to go grab info from the LAST workbook created to keep a running total.
New to this forum, if there's a way to attach a copy of the two workbooks we use now please tell me. Looking at what we are using would probably make a lot of this clearer.
Thank you!!! PQ
It sounds like you have a working solution using Excel, which is very good. Oftentimes the biggest challenge is figuring out the process flow and all its branches. Further it seems like you just want to make your solution more routine and sustainable to work with.
Although making a souped-up macro-enabled Excel document sounds like the right way to go, the features you are asking for are really more suited for a relational database. Not to say it can't be done, but implementing an Excel based solution is going to be messy. The crucial difference I believe is maintaining the the logical link between the trip sheet and the log sheet.
For example, if I understand correctly, you will have to create several Excel files, and they are going to need a naming convention in order for the computer to know which ones to look for. This exposes the data to the most basic mishaps like mistakenly renaming or moving a file. If you will be the only one to maintain the system, then perhaps that won't be an issue, but experience tells me that a lot of effort can be instantly undermined by something as simple as opening a file and editing it.
This also means that you will have to maintain a "builder" file that must contain the code you develop. Not every machine is set up for macros, and a lot of end-users will get scare notices that, "this document contains macros which could be a danger...blah blah blah." Which means every output file should probably be macro free.
Instead I would recommend recreating your system using a relational database like MS-Access. You can create unlimited number of records/tables, and use any number of variables to maintain the logical link (by log #, by date, by flight #, etc.). You can also set the rules so data can be recorded and reported in a consistent manner. And if you have the need and the programming expertise, VBA macros can also be introduced to an MS-Access based solution.
Lastly, all the data could easily be kept in one central *.mdb file, which would be far easier to maintain and backup than several overlapping excel files.

How do I automate a report on variance in the same SQL table fields on monthly basis?

I have a T-SQL view with integer fields. I need a report on a monthly basis regarding the difference from one month to the next, i.e. so many people were engaged in a particular activity on 8am of the 1st of this month, so many the previous month, here is the difference. The numbers fluctuate all the time. I need a variance between 2 snapshots in time.
I am using the SSRS, however in reporting services I can only display the "current" situation. I could run a report at 8am of the 1st of each month and then calculate the differences manually. But how could I automate this calculation and then report on the difference?
I have tried to import data from SQL to 1 Excel spreadsheet from 1 month, then to the 2nd spreadsheet from the 2nd month. The 3rd spreadsheet calculates the difference. But how do I create a nice looking report from Excel?
Additionally I cannot send the report by email. It has to be available online.
Furthermore, each office wants their figures to be confidential and not visible to another office.
Thanx in advance.
Can you add a UserCount table that stores each office's user count for each month? It could have columns like:
id
date
user_count
office_id
You would insert a new row each month based on what the view tells you that month for each office. Then it's as simple as exporting that table to Excel and graphing it using Excel's built-in graphing tools.