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

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*

Related

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.

Passing value from master to corresponding sheet

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!

Remove Duplicates in SSRS Subreport

I have an SSRS report the links a line item subreport to my main report by an order number. When a customer orders 2 line items, 2 order numbers come in with contact info, etc. In the SSRS report, the order number shows up twice and the multiple line items fall below. What I would like is the 1 order number with the line items following.
As I have it now it looks like:
Order# Contact User
1234 J. Smith JS1
LineItem Qty Order Date
1 3 05/15/2015
2 2 05/15/2015
Order# Contact User
1234 J. Smith JS1
LineItem Qty Order Date
1 3 05/15/2015
2 2 05/15/2015
I tried =Fields!LineItem.Value =PREVIOUS(Fields!LineItem.Value) but because the dup isn't directly previous that didn't work.
But I'd like to have just one single result. Any help would be great.
At the bottom of your design screen should be the Row Groups window. Many times, you will already have a group created. If you right click on it and click the properties it should look something like the image below:
Thanks.

MySQL Column that shows order of items

I'm new to MySQL procedures and triggers and constraints and I'm wondering how I can set one of my columns to be dependent on another column. For example, I have a table of products and weekly sales similar to:
Product_ID Sales Ranking
1 13
2 12
3 543
4 435
5 97
I want my ranking column to be automatically updated whenever a value in the sales is updated or a new value is inserted (this table will only hold at most 50 products), which means product IDs will come and go. How can I set it so that the Ranking is always an x value such that x represents what position it would be it the product id was ordered by sales DESC?
Product ID is NOT an AI column or Primary Index

ClosedXML Outline

I am trying to create a Group in the exported Excel Workbook using OpenXML.
My source data table looks like this:
Row State Product Sales
1 NY A 100
2 NY A 200
3 NY B 300
4 CA A 100
5 CA A 200
6 CA B 300
I would like to create an outline by State and then Product with a subtotal on each group
I tried
ws.Outline.SummaryVLocation = XLOutlineSummaryVLocation.Top;
ws.Rows(1, 3).Group(); // Create an outline (level 2) for rows 1-4
ws.Rows(4, 6).Group();
But it's not giving me what I want, and I don't see an option to add the subtotals.
How can I achieve this?
The code example in the documentation which you use is either outdated or just wrong.
If you want to group rows 2 to 4 you need to use the code ws.Rows(3, 4).Group(); (see picture). This is consistent with Excel itself, there you have to select only rows 3 and 4 before clicking the group button to get the same result.
When you try to group rows 1 to 3 like in your code you group them all under row 0 which leads to errors since there is no row 0.
You can control this behaviour to some extend with the XLOutlineSummaryVLocation property. If you use Bottom instead of top you use the top two rows to group rows 2 to 4: ws.Rows(2, 3).Group();
With all this said two more points:
You need to use Excel row numbers not the numbers in your column "Row".
All this grouping and collapsing is only for display purposes. To sum up the sales numbers you have to use the subtotal functions in Excel (which I find rather confusing and unhelpful in this case) or add columns and results directly in C#.
Using this code should lead to your desired result (see picture below):
ws.Outline.SummaryVLocation = XLOutlineSummaryVLocation.Top;
ws.Cell(1, 5).SetValue("Product subtotals");
ws.Cell(1, 6).SetValue("State subtotals");
ws.Rows(3, 4).Group(); // group rows 2 to 4 (state NY), outline level 1
ws.Cell(2, 6).SetFormulaA1("=SUM(D2:D4)"); // subtotal for all NY sales
ws.Row(3).Group(); // group rows 2 and 3 (product A), outline level 2
ws.Cell(2, 5).SetFormulaA1("=SUM(D2:D3)"); // subtotal for all NY, product A sales
ws.Cell(4, 5).SetFormulaA1("=SUM(D4)"); // subtotal for all NY, product B sales
ws.Rows(6, 7).Group(); // group rows 5 to 7 (state CA), outline level 1
ws.Row(6).Group(); // group rows 5 and 6 (product A), outline level 2
ws.CollapseRows(2); // collapse group level 2 (products)