Passing value from master to corresponding sheet - google-apps-script

I have google sheet collecting data from 7 other sheets of the same structure. Each of the sheet has its own owner, they fill the info and the final column is the "approved" col that they leave empty.
Now what I want to do is to be able to approve those rows from the master sheet.
Master sheet collects the info from the other sheets using query and multiple importrange functions and filter out rows that have null value in the first column or have a "approved" column = 'yes'.
So what I want to happen is approving those rows from the master and as soon as that happens they should disappear from master. What's the best way to create communication that communication? This is probably important - combination of 3 columns would create a unique id of the row.
Sheet 1
Date Name Sheet Approved
2020-01-01 A 1
2020-01-02 B 1 Yes
Sheet 2
Date Name Sheet Approved
2020-01-01 C 2
2020-01-02 D 2
Sheet 3
Date Name Sheet Approved
2020-01-01 E 3 Yes
2020-01-02 F 3
Master
Date Name Sheet Dummy* Approved
2020-01-01 A 1
2020-01-01 C 2
2020-01-02 D 2
2020-01-02 F 3
*Using dummy to filter out rows already approved
and now as soon as I add approved in Master for name A, I want that cell to change in sheet 1 (and using my query function filter it would disappear from the Master)
Master
Date Name Sheet Dummy* Approved
2020-01-01 A 1 Yes
2020-01-01 C 2
2020-01-02 D 2
2020-01-02 F 3
Sheet 1
Date Name Sheet Approved
2020-01-01 A 1 Yes
2020-01-02 B 1 Yes
Master
Date Name Sheet Dummy* Approved
2020-01-01 C 2
2020-01-02 D 2
2020-01-02 F 3
Any ideas or directions?
Per suggestions - added links to sheets I already have (limited to 2 owners since it doesn't matter atm)
Master
https://docs.google.com/spreadsheets/d/1a6XoQvmGNSq3D0t5eaVXHoYBmSTVhn4T7GUMdmscWvE/edit?usp=sharing
Owner1
https://docs.google.com/spreadsheets/d/1hjs7hoKqDEsGEdyMmWRlrlBer4w7dcV4TH8I1FSvwjk/edit?usp=sharing
Owner2
https://docs.google.com/spreadsheets/d/1WJ1LiZixmrtla3BFAaUOWyQ_SfFfZIT-I38138X4cNE/edit?usp=sharing

I am sure many solutions exist, my thought would be to have the other 7 sheets import to a tab in the owner's sheets. Then in each owner's sheet for the Approved cell write a query to return the Approved column from the imported sheet using the combination of 3 columns that create the unique id of the row.
Update:
I am working with the shared sheets you shared and I added a tab to the Owner 1 sheet to import the data from the master. I then added a formula in F2 for sheet1:
=if(isna(query(MasterImport!$A$1:$F,"SELECT F WHERE A = date '"&TEXT(A3,"yyyy-mm-dd")&"' AND B ='"&B3&"' AND C = '"&C3&"' LABEL F ''",1)),"",query(MasterImport!A2:F,"SELECT F WHERE A = date '"&TEXT(A3,"yyyy-mm-dd")&"' AND B ='"&B3&"' AND C = '"&C3&"' LABEL F ''",1))
However, it seems to be creating a circular reference of sorts and Sheets keeps showing and removing so this approach will not work.
So, I added a tab to the master sheet importing all owner sheets where the date col is not null and changed the query range in sheet1 to the OwnerImports tab.
=QUERY(OwnerImports!A2:F, "select * where F is null",0)
I also changed the formula in the owner sheet to query the OwnerImports tab instead of Sheet1.
=if(isna(query(MasterImport!$A$1:$F,"SELECT F WHERE A = date '"&TEXT(A3,"yyyy-mm-dd")&"' AND B ='"&B3&"' AND C = '"&C3&"' LABEL F ''",1)),"",query(MasterImport!A2:F,"SELECT F WHERE A = date '"&TEXT(A3,"yyyy-mm-dd")&"' AND B ='"&B3&"' AND C = '"&C3&"' LABEL F ''",1))
I believe it is working. You would mark the row Accepted in the OwnerImports tab and it is reflected in the Sheet1 tab.
There does seem to be some lag on the owner sheet, refreshing the sheet helps. This was a hairy one!

Related

Google Sheet - How to create a link to a cell, which will also update the destination cell value when clicked?

I am building a dashboard on google sheet for the first time.
On tab 'Restaurants', I have summed sales grouped by restaurant names
restaurant_name
sales
A
100
B
250
On tab 'Orders' are dimensions and metrics at order level
restaurant_name
order_id
A
123
A
456
B
123
B
456
The cell A1 in 'Orders' allows to filter orders from one specific restaurant by inputing the restaurant name.
I would like to add a column in the 'Restaurants' tab with links directing to 'Orders'!A1 and updating A1 value with the according restaurant_name (A or B).
restaurant_name
sales
link
A
100
orders_detail(link)
B
250
orders_detail(link)
Ideally I am looking for a no code solution which allow me to add a parameter to the A1 cell link
https://docs.google.com/spreadsheets/d/ABCDqHgy_y7RqBE-kdRkwmg/edit#gid=999&range=A1*&new_value=B2*

Google Apps Script - When a new data containing row is added to Sheet 1, move that to a new row in Sheet 2, then clear the data from Sheet 1

Row 1 in both Sheet 1 and Sheet 2 are frozen, with column names.
Once I have a working script, I will setup a corresponding onChange trigger to execute the script.
Due to the way new data containing rows are added to Sheet 1, the script itself cannot be written with onChange/onEdit syntax, I just need a function that works, and I'll use an onChange trigger to execute it.
Step 1:
Sheet 1 - a new data containing row was added (Row 2).
A
B
C
1
City
State
Country
2
Los Angeles
CA
USA
Sheet 2 - the data from Sheet 1 - Row 2 should be copied to the next available row, which in this case would be Row 2.
A
B
C
1
City
State
Country
2
Los Angeles
CA
USA
Step 2:
Sheet 1 - after the data from Row 2 has been copied to the next available row in Sheet 2, then Row 2 should be cleared.
A
B
C
1
City
State
Country
2
blank
blank
blank
Step 3:
Sheet 1 - a new data containing row was added (Row 2).
A
B
C
1
City
State
Country
2
Miami
FL
USA
Sheet 2 - the data from Sheet 1 - Row 2 should be copied to the next available row, which in this case would be Row 3.
A
B
C
1
City
State
Country
2
Los Angeles
CA
USA
3
Miami
FL
USA
Step 4:
Sheet 1 - after the data from Row 2 has been copied to the next available row in Sheet 2, then Row 2 should be cleared.
A
B
C
1
City
State
Country
2
blank
blank
blank
...and so on
Sheet 1 should only ever have two rows. Row 1 for the column names and Row 2, which will be blank to start, then filled with data (which should then be copied over to Sheet 2), then cleared so that it is blank again, repeat.
Sheet 2's row count should be continually growing, one by one, as individual data containing rows populate into Sheet 1 - Row 2 over time and get copied over.
The incoming data that fills Sheet 1 - Row 2 comes from an external app, I'm never manually entering data into that sheet/row. The incoming data fills all columns in Sheet 1 - Row 2, all at once.
Try
function onOpen() {
SpreadsheetApp.getUi().createMenu('⇩ M E N U ⇩')
.addItem('👉 Transfer data form Sheet1 to Sheet2', 'moveData')
.addToUi();
}
function moveData() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var rng = ss.getSheetByName('Sheet1').getRange('A2:C2')
ss.getSheetByName('Sheet2').getRange(ss.getSheetByName('Sheet2').getLastRow()+1,1,1,3).setValues(rng.getValues())
rng.clearContent()
}

App script don't take filtered pivot table values into account

I have a google sheet containing a pivot table whose values are read by another table and on which slicers are applied.
When the slicers are used to filter the value, my app script recompute the values for display in the other table.
The issue is that in my script, the read values are unfiltered despite the view in the sheet being correctly updated regarding applied filters.
The function sheet.getRange(row, column).getValue() gets the unfiltered values of the table and not the filtered values as displayed in the sheet.
So when i apply filters to my pivot table on my sheet, it's well filtered and dispalyed in the sheet but my script seems to not see that the pivot table have been filtered and works on the unfiltered pivot table.
More precisely:
My script creates a pivot table and use its data to fill-in formulas in another table.
For example:
Data Source Table:
Project
Type
Cost
End
Project 1
Type_1
2600
2021
Project 2
Type_2
3500
2022
Project 3
Type_1
1200
2021
Project 4
Type_2
2350
2022
Project 5
Type_2
3350
2022
Pivot Table:
Col H
Col I
SUM of Cost
Project_Type
Project_Type
Project
Type_1
Type_2
Project_1
2600
(Row 4)
Project_2
3500
(Row 5)
Project_3
1200
(Row 6)
Project_4
2350
(Row 7)
Project_5
3350
(Row 8)
Table with formulas calculated from Pivot Table:
Type_1
3800
(=SUM(H4:H8))
Type_2
9200
(=SUM(I4:I8))
I use slicers to filter the pivot table.
Depending on applied filters, it happens that rows or columns disappear as there are no data to display for these rows or columns, which leads to
wrong values for fomulas being calculated on pivot table.
For example:
If I apply a filter on Project_Type to keep only Type_2 on the Pivot table, I get the following result:
Pivot Table:
Col H
SUM of Cost
Project_Type
Project_2
3500
(Row 4)
Project_5
3350
(Row 5)
Table with formulas calculated from Pivot Table:
Type_1
9200
(=SUM(H4:H8))
Type_2
(=SUM(I4:I8))
So I added a button to relaunch the script which compute formulas on the filtered pivot table.
My problem is that the script is executed on the pivot table data as if it wasn't filtered, whereas the sheet properly displays the filtered pivot table.
In the example:
SHEET.getRange('H4').getValue();
returns the value 2600 instead of 3500 as if it was reading the values in the unfiltered pivot table.
How can i get the filtered pivot table from my script?
Thanks in advance for your help.

Auto fill a column in Google Sheets with formula when new row is added (without arrayformula)

Similar to Auto fill a column in Google Sheets with formulas when new rows are added where I have a Zapier that auto-populates a specific worksheet in a google sheet.
I have Columns A through F. The F column has an associated formula to it (referencing the C column in the same row) that I'd like to have applied when a new row is auto-generated above it.
Note: I can't use arrayformula because Zapier will assume that the row has content and will open a new row above it
Example of google sheet
A B C D E F G
1 Name Email Lecture Date Quiz Score Code
2 Neil foo#bar 2 5/5 4 Pass (formula ref C2)
3 Rose bar#foo 10 4/5 5 Failed (formula ref C3)

How to get the last entry containing a certain value in Google Spreadsheet

I have an answer spreadsheet linked to a Google form. I wish to get the last date that and answer was submitted.
Lets say I my entries look like this :
DATA :
A B
1 Date String
2 2015-05-09 Abb
3 2015-05-11 Bcc
4 2015-05-12 Cdd
5 2015-05-20 Bcc
6 2015-06-01 Abb
The result that i want would look like this :
A B
1 String Last date
2 Abb 2015-06-01
3 Bcc 2015-05-20
4 Cdd 2015-05-12
Ideally, I would like to do so with formulas only!
Assuming your data starts in row 2, try:
=ArrayFormula(iferror(vlookup(unique(B2:B), sort({B2:B, A2:A}, 2, 0), {1, 2}, 0 )))
Change ranges to suit. Don't forget to include the sheetname if you need that formula to appear on another sheet.