How to generate unique trip id focusing some specific parameters? - google-apps-script

I need to operate around 15-20 trips per day using different sized trucks round the year. I need to generate Unique Trip ID in googlesheet based on date, month, year, truck size, transporter and the number of the trip on the day. The trip IDs will be unique in the column and input in Column U. The available trucks size are L-23, L-20, M-18, M-16,S-14,S12,T-10, T-8. Truck size is input in Column S. Transporters are MLS, TLT and AHK which is input in Column T. Suppose, a trip with truck size, S-12, will move on 25th June 2022,Saturday and the Transporter is MLS. So the unique trip id will be MLS1225062201 where MLS is the transporter,12 is the truck size, 25 is the date, 06 is the month, 22 is the year and 01 is the number of the trip on the mentioned day.
For more, here is the link of googlesheet https://docs.google.com/spreadsheets/d/1LeeWIHomcnk_sPahLNJ8pXeDEz1tjSGEoQGa3ulxiKU/edit?usp=sharing
Is it possible to generate using google apps script or any other formula?

Use the formula:
=arrayformula(if(B2:B="","",(U2:U&query(split(T2:T,"-"),"SELECT Col2",0)&text(B2:B,"ddmmyy")&TO_TEXT(A2:A))))
Try adding a trip no. to for your team to fill up to help with the formula I provided
Since its an arrayformula, it will autogenerate based on the details you have normally filled in. I have done a version in the sheet you have shared.
https://docs.google.com/spreadsheets/d/1LeeWIHomcnk_sPahLNJ8pXeDEz1tjSGEoQGa3ulxiKU/edit#gid=1170569363

Related

google spreadsheet Real time importrange not reliable

I have 2 google spreadsheet
a membership database // with 8 column of data for 1 record. Currently there are around 3000 record in the sheet and it is growing at a rate of around 1500 records per month. New members enter these info via a google form. And then I wrote some apps script to assign membership number to each record in numeric order e.g. KS000001--->KS000002 with onSubmit trigger.
a sales record // which import the entire membership database with function importrange and record sales.
Whenever I enter a sales record, I need to check if he is a registered member in real time and match the sales record with the respective membership number.
Sometimes the importrange just doesnt work and shows #REF
This is the function I use
=ImportRange("xxxxsheetidxxxxxx","Membership DB!A1:I5000")
Is there a more reliable way to do this? I need this in real time for today newly joined member.
The idea I have in mind is to cut the database into two parts and update it everynight.
Method:
Copy the entire membership database to the sales record at 12:00am. e.g. record (KS000001-KS003000). Use importrange to import the newly joined member during the day e.g. record (KS003001 - latest). Both array are in the same column A:I for easier look up.
Is there any better alternatives?
Thank you

Laravel array filtering

Developers, I am working on a report that I have to display the companies ranking based on some conditions for the date range which comes from front. Ex: last week, I have done that, but now I want to show how many weeks that a particular company be in same rank. If I am checking the past week I have to check the ranking for each week from the year start. If last week first position company and other weeks first position company is same I have make the count as increasing accordingly. When I querying the data for each week using the for loop it is taking around 42s to process and display the data. Also I tried to fetch whole data from first week of the year to current week then I filtered the array but this also takes long time. Can anyone give any other ideas to overcome this? Thanks in advance.
As far as I understand your problem - then storage of aggregated data should help you.
Create a table in the database, let's say "archive_rating", with 3 fields: week_number (let from January 1, 2000), company_id, company_position in your rating. Don't forget the index for the week_number field.
At 00:00:00 every Monday, run a background task that will save the positions for each company to an archive table.
This will allow you not to calculate a rating for each week from the beginning of the year. You will already have it.

Unique ID Generator (Google Forms/Google Sheets/Google Studio)

I am currently working with health data and I wanted to create a visual on google studio that shows that amount of time a player missed due to each injury. However I am only able to show the total sum of the time missed due to an injury if a player suffered two of the same injuries. For example, a player suffered a knee injury in May that resulted in him missing 25 days. He then suffered another knee injury in July that resulted in him missing 15 days. The graph would show that he has missed 40 days due to a knee injury instead of Knee Injury 25 days, Knee Injury2 15 days. I believe the only way I can solve this issue is if I have a unique ID for each Injury. We currently update our google sheets through google forms. So I am wondering if there is a way to create an array formula of some sort that generate a unique ID when there is a value in the Injury column. If the Injury column is blank I want the ID column to be blank as well.
Any suggestions? I've looked into Google Script coding but having trouble with that.
Sorry for the lengthy post.
Thanks
-- Addition --
I am also hoping to have a bar graph show the data above. So for example I have the Player Name Column as a Dimension, the Injury Column as the Breakdown Dimension, and then some kind of calculated field that sums the Time Missed (Days) column by the Injury ID column.
You can use a custom formula like this:
function generate_ids(values) {
values = values.map(row=>row[0])
const ids = values.map(val=>[val?Utilities.getUuid():''])
return ids
}
Use the formula in your sheet as:
=generate_ids(A2:A)
If injury data is stored in column A starting from row 2, or adapt the range reference according to your sheet setup.

How to effectively store data of varying time framces

I have a form that captures production data for a certain process. When a employee enters production numbers, currently I am not sure what the time frame for the production numbers are.
E.g. Employee A enters a production number of 50 on 2017/10/02. This 50 represents the production of 1 day (2017/10/01). Now, employee B enters 550 on 2017/10/03, but this represents production for the week of 2017/09/24 to 2017/10/01.
Now, we know that various employees will be providing data of different time frames, but I'm trying to figure out the best way to manage this. I capture data using a Excel sheet with VBA, and then transfer it to a SQL database. Currently, in the database we use GROUP BY to get all data related to a certain month. So if the timestamp of the data is in September, all September data will be summed and the total used as the September total to date. However, this does not answer two key points:
If data for September is entered in October.
If data is entered that duplicates a period for the employee that was entered earlier.
What is the best way of managing this? I can change my capturing form and the way we manage data in the database.
EDIT and more information:
The information I want to capture consists of production numbers from various production areas entered by an employee. So for example, site A will have 3 sub-sites. These sub-sites will each have a production achieved, target for the period and forecasted production number.
Timestamp: Site: Sub-site: Production: Target: Forecast:
2017/10/01 PlaceA Line1 200 250 230

Copying values from one table with blank cells in between to another table with no cells in between

I'll try and explain this as basically as possible. We have a long list-like table with dates in the first column for each working day then a list on individual piercings we have completed with their respective prices and then daily totals in this format:
Date Piercing Price Daily Total
26/10/13 ear £9.50
navel £30 £39.50
28/10/13 nose £17.50 £17.50
29/10/13 ear £9.50
nipple £25
eyebrow £25 £59.50
etc
etc
As you can see the column which holds the daily totals will have a lot of blank cells in between. So what we have done is made a separate sheet with a list of dates and are hoping to find some form of lookup function which can read the existing "Daily total" column and copy only the cells which have values over in order that they appear so they match up with the right dates like this:
26/10/13 £39.50
28/10/13 £17.50
29/10/13 £59.50
etc
etc
If anyone can lend me as easy way of achieving this I will be most grateful as neither of us are talented with writing our own functions or statement codes.
If you are just looking for a list of dates and daily totals, assuming the daily totals have already been calulated and you never have negative transactions then this should work
SELECT date, MAX(DailyTotal) FROM peircings GROUP BY date;
OR
SELECT date, DailyTotal FROM peircings WHERE DailyTotal!='';
It's hard to know which one might even help you without a better understanding of your database and how you want to use the data.