i try to pull last paymant day in this example.
I try vlook and this Find the last match from two columns but i dont have items.
date Action Payment Last payment date
08.01.2022 Payment 100
09.01.2022 other action
10.01.2022 other action
11.01.2022 other action
12.01.2022 other action
13.01.2022 other action
14.01.2022 other action
15.01.2022 Payment 107
16.01.2022 Payment 108
17.01.2022 Payment 109
18.01.2022 other action
19.01.2022 other action
20.01.2022 other action
21.01.2022 other action
22.01.2022 Payment 114
Given the data below:
Use the query formula to get the last payment date:
=query(A2:B, "select A where B = 'Payment' order by A desc limit 1")
Output:
Related
I have a Google form accepting data from different users, which goes to a sheet and is used to SUM the values across columns at the end of the day. The problem is that users can re-submit forms to update the data totals if there is a change at the end of the day:
NAME K L M
ALF 4 0 1
BILL 1 0 0
SALLY 1 0 1
DENNIS 1 1 1
RICK 0 0 1
SALLY 2 1 1 <--- SALLY RESUBMITTED HER FORM AGAIN WITH UPDATED VALUES
In my current Query, I SUM() the columns after filtering by the date like this:
SELECT SUM(K), SUM(M), SUM(N) WHERE C = date '"&TEXT($B$1,"yyyy-mm-dd")&
$B$1 is a cell with a datepicker and col C is the user submitted form date. Col A has the unique form generated submission timestamps
As you can see, the SUM for each column will be off by the extra submission from Sally. I need to include only the most recent submissions from any of the users, and ignore any prior ones for this date. I'm not sure how to filter in this manner and sum just the most recent instance from each unique user.
** EDIT **
I should note the original form data is on another sheet and the cells are referenced via a query to this range. The form is also submitted daily, so the query must be able to specify the date in question for summation of entries.
Give a try on following formula-
=QUERY(INDEX(REDUCE({0,0,0,0},UNIQUE(J2:J7),LAMBDA(a,b,{a;SORTN(FILTER(J2:M7,J2:J7=b,C2:C7=date(2023,2,17)),1)})))," select sum(Col2), sum(Col3), sum(Col4)")
If you actually want most recent response to sum then use-
=QUERY(INDEX(REDUCE(SEQUENCE(1,COLUMNS(A2:M7),0,0),UNIQUE(J2:J7),LAMBDA(a,b,{a;QUERY(SORT(FILTER(A2:M7,J2:J7=b),1,0),"limit 1")}))),"select sum(Col11), sum(Col12), sum(Col13)")
Here you have another option, creating an auxiliary column that returns 1 if it corresponds to the date and is the last timestamp
=QUERY({K:M,
MAP(A:A,C:C,J:J,LAMBDA(ts,date,n,IF(date<>B1,0,IF(ts=MAX(FILTER(A:A,J:J=n,C:C=date)),1,0))))},
"SELECT SUM(Col1),SUM(Col2),SUM(Col3) where Col4=1")
Overview
I have inserted order data into a spreadsheet through spureadsheets api.
After that, I need to update the order data once inserted in the spreadsheet so that the customer can transfer the fee and the administration can process the shipment.
I would like to get the cell range where the updated order data exists and update the values in the corresponding cell range.
Can someone please help me with this?
The problem that is happening
Here I want to insert the following data into the range A5 to G5 on my spreadsheet. => (Wednesday, 12004, paid, 2021-11-05, jolly, 0145)
However, I want to get the cell range A5-G5, which is the cell position where the updated order data exists, but I don't know how to get the cell range using the API.
Processing test that I did
I was not able to get the cell location where the updated order data was located, so I tried to test by passing the range I wanted to update directly to the $range variable. However, it did not update correctly in the cell position A5-G5 where the updated order data was located.
1.$range = $sheet_ym.'!A1:""'; //I specified column A1 and an empty string, but got an error message.
2. $range = $sheet_ym.''; //No column and only an empty string forced the top row to be overwritten instead of the row with the updated order.
3. $range = $sheet_ym.'; !A1:A1000 //I got an error message when I specified column A1 + row A1000 => "Requested writing within range ['202112'!A1:A1000], but tried writing to column [B]" ["domain"]=> string(6) "global" ["reason"]=> string(10) "badRequest' }
4. $range = $sheet_ym.'!A1:O1000'; //Specifying A1 and O1000 forced the top row to be overwritten instead of the row where the updated order exists.
What I need support for.
Can you please tell me how to get the position of the cell where the updated order data exists, or how to specify a value for $range and automatically update the data in the appropriate cell range according to the updated order data
Every time I confirm a payment or complete a dispatch on the application side, the function insertif in the source code is triggered and the order data is inserted into the spreadsheet.
If I find duplicate values in the order_id, I want to overwrite the cell data in the row where the duplicate data exists. (I am unable to implement this correctly.)
In the sample you can see what happens when the data in the row with an order_id of 12004 (in the range A5 - G5) is updated.
When the payment is confirmed, the values C5 and D5 are updated.
When the payment is confirmed and the shipment is completed, the value of E5 is updated.
If no duplicate values are found in the order_id, then the data will be added to the last row in the spreadsheet. (I've already implemented this and it works fine.)
The state of the spreadsheet before the payment confirmation on the application side
sheet name = 202111
(order_id = 12004)
A
B
C
D
E
F
G
1
week
order_id
is_paid
paid_day
send
name
account_id
2
Monday
12001
mercy
0123
3
Monday
12002
paid
2021-11-02
send
kate
0153
4
Tuesday
12003
paid
2021-11-5
tarkey
0097
5
Wednesday
12004
jolly
0145
6
Thursday
12005
paid
2021-11-06
send
rashford
0083
The state of the spreadsheet when the payment has been confirmed on the application side, but the shipment has not been processed
sheet name = 202111
(order_id = 12004)
A
B
C
D
E
F
G
1
week
order_id
is_paid
paid_day
send
name
account_id
2
Monday
12001
mercy
0123
3
Monday
12002
paid
2021-11-02
send
kate
0153
4
Tuesday
12003
paid
2021-11-5
tarkey
0097
5
Wednesday
12004
paid
2021-11-6
jolly
0145
6
Thursday
12005
paid
2021-11-06
send
rashford
0083
The state of the spreadsheet when both payment confirmation and dispatch processing are done on the application side
sheet name = 202111
(order_id = 12004)
A
B
C
D
E
F
G
1
week
order_id
is_paid
paid_day
send
name
account_id
2
Monday
12001
mercy
0123
3
Monday
12002
paid
2021-11-02
send
kate
0153
4
Tuesday
12003
paid
2021-11-5
tarkey
0097
5
Wednesday
12004
paid
2021-11-6
send
jolly
0145
6
Thursday
12005
paid
2021-11-06
send
rashford
0083
SourceCode
function api_insertif($sheet_name=NULL,$current_date=NULL,$where=NULL,$input_data=array()){
$sheet_name=isset($sheet_name)?$sheet_name:'monthly';
$current_date=isset($current_date)?$current_date:date('Y-m-d');
$where=isset($where)?$where:'';
//The $input_data contains the customer order information.
$input_data=isset($input_data)?$input_data:array();
//A flag to separate insert and update operations on the spreadsheet
$insert=false;
//Set the new insertion flag to true
$insert = true;
//Sheet name (taken from the current year, e.g. 202110,202111)
$sheet_ym=isset($sheet_ym)?$sheet_ym:date('Ym');
//Receipt number of the order customer is trying to confirm
$duplicate_check_id = $input_data[0]['orderid'];
//Extracting order information from the worksheet
$worksheet_order_val = $worksheet['values'];
//Check that there are no duplicate orderids in the worksheet.¥¥
foreach($worksheet_order_val as $sheet_val){
if($sheet_val[2] == $duplicate_check_id){
var_dump('There is a duplicate order ID.');
$insert = false;
}
}
var_dump('The insertion or update process has been checked.');
//If it is a new order and not an update of the order data
if($insert){
//The $inputdata contains the data of the order when the order is actually placed or when the management confirms the payment.
foreach($input_data as $row_data){
//Exception handling starts
try{
$client = $this->google_client;
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'myspreadsheetid';
//202109, 202110, 202111, etc. The year and month are used as the sheet name.
$sheet_ym=isset($sheet_ym)?$sheet_ym:date('Ym');
$range = $sheet_ym.'!$A1';
$option = [
'valueInputOption' => 'USER_ENTERED'
];
$requestBody = new Google_Service_Sheets_ValueRange([
'values' => [
[
$row_data['week'],
$row_data['order_id'],
$row_data['is_paid'],
$row_data['paid_day'],
$row_data['send'],
$row_data['name'],
$row_data['account_id']
]
],
//Inserting new order data into a spreadsheet
$service->spreadsheets_values->append($spreadsheetId, $range, $requestBody,$option);
var_dump('Order number has been successfully completed and inserted');
}catch(Exception $e){
//Handling data insertion failures
var_dump('function api_insertif() : Failed to insert some data');
var_dump($e);
return false;
}
}
//===============================================================================
//From here on down is not an insertion, but a process to update the spreadsheets
//===============================================================================
}else{
foreach($input_data as $row_data){
//Exception handling starts
try{
var_dump('The same order number as the current order exists in the spreadsheet, so update it.')
$client = $this->google_client;
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'myspreadsheetid';
$option_1 = [
'valueInputOption' => 'USER_ENTERED'
];
$option_2 = 'USER_ENTERED';
//Define the RequestBody
$updateBody = new Google_Service_Sheets_ValueRange([
'values' => [
[
$row_data['week'],
$row_data['order_id'],
$row_data['is_paid'],
$row_data['paid_day'],
$row_data['send'],
$row_data['name'],
$row_data['account_id']
]
],
]);
//Update process
$service->spreadsheets_values->update($spreadsheetId, $range, $updateBody, $option_1);
var_dump('The insertif update process is now complete.');
}catch(Exception $e){
var_dump('The update process of insertif could not be performed.');
var_dump($e);
exit;
return false;
}
}
}
Libraries and external services used
google-api-php-client--PHP5.6 v2.11.0
https://github.com/googleapis/google-api-php-client/releases
Google Cloud Platform
https://console.cloud.google.com/
The page I am referring to
php google api client
https://github.com/googleapis/google-api-php-client
Migrate from Sheets API from v3 https://developers.google.com/sheets/api/guides/migration#v4-api_5
PHP QuickStart
https://developers.google.com/sheets/api/quickstart/php
I am trying to get the Title of the employee once he or she gets promoted.
I have the data of the employees logged the time in the timesheet that means I have the date with month in a sheet called the Main sheet. There is one helper sheet I have built that has the promotion details. Now I want to get these titles on the Main sheet.
Use Cases:
For instance, In the Main sheet, we have the data like this:
Date Name Hours Title
2019-01 Max King 10 to get from Helper Sheet
2019-02 Max King 20 to get from Helper Sheet
2019-03 Max King 30 to get from Helper Sheet
Now in the Helper Sheet, I have this data
Date Name Title
2019-01 Max King Trainee
2019-03 Max King Senior
Now in the above scenario, I dont have 2019-02 date in the Helper sheet so that I can easily bring the Title. In the Main Sheet, Against 2019-02 I want to bring the title Trainee.
Can someone please guide me?
Thanks
Here is the link to data:
https://docs.google.com/spreadsheets/d/1hfXCFTp_vLqPFjazM-Vo6-3o8J1td1zpnCJOeK1LBg0/edit?usp=sharing
Helper Sheet
Main Sheet
I have added a new sheet ("Erik Help") with the following formula in C1:
=ArrayFormula({"Title";IF(A2:A="",,IFERROR(VLOOKUP(A2:A&B2:B,SORT(FILTER({Helper!B2:B&Helper!A2:A,Helper!D2:D},Helper!B2:B<>"")),2,TRUE),"NOT FOUND"))})
This one formula produces the header and all results for C2:C.
You may change the header text within the formula as you like.
Essentially, the combined name-date is looked up within a sorted virtual array of the name-date and title from the "Helper" sheet, and the title (column 2 of that array) is returned if found. The final parameter of the VLOOKUP is TRUE, which means the search column is in strict sorted order and, if no exact match is found, to back up and grab the closest match before the searched one.
I'm trying to make a budget sheet for a trip.
I have 2 sheets in a Google Spreadsheet. One contains the steps of the trip. The other contains a dashboard with the sum for each of these 5 groups of steps: "food", "activities", "shopping", "hotels" and "vehicle".
My first sheet is like that (with 4 columns - the 3rd is the price):
1. Go to museum 45 Activity
2. Playing cards 5 Activity
3. Sleeping at Bohaha Hotel 123 Hotel
4. Take breakfast 10 Food
In the other sheet, I want to make different sums conditioned by the value of the 4th column, and using the values of the 3rd column.
The result of the second sheet in this example would be:
Food 10
Activities 50
Shopping 0
Hotels 123
Vehicle 0
How can I do that?
I can use a function if necessary.
Simple SUMIFS:
=SUMIFS(Sheet1!C1:C99, Sheet1!D1:D99, A1)
Assuming description in second sheet matches description in 4th column (the formula is not going to do the stemming for you to convert Activity to Activities - you can use 1 column for exact match string and 1 column as reporting label...)
I found the perfect formula :)
=SUM(FILTER('Sheet 1'!H5:H; 'Sheet 1'!G5:G="Food"))
I've got a Google Form that gathers data into a Google Sheet #1 (say, requests from employees to work on certain days).
My goal is to make a pretty-print list of people who requested to work this week Saturday and Sunday.
Looks like I need to have the data from sheet #1 appear at sheet #2 if it meets certain criteria - all the employee names who's working day from sheet #1 equals to this Saturday.
How can I automatically have in sheet #2 certain data from sheet #1 that meets a criteria?
How can I describe the criteria 'smth equals to this Saturday and Sunday'?
How can I create an output Google Form from sheet #2 formatted nicely ready to print?
Please try:
=query(Responses!A:E,"Select C,D,E where B < date '"&text(today()+6,"yyyy-MM-dd")&"' and (dayOfWeek(B) = 1 or dayOfWeek(B) = 7)")