Sheets Formula Works with Iterative Calculations but data gets very messy very fast (with GIF) - google-apps-script

Picture: Sheet Document
OVERALL EXPLANATION OF DOCUMENT AND WHAT IS WHAT:
I have a Google Sheet document (Picture ↑) with
Products (Product Category and Name) - Columns B:D
Prices (Weight, Prices with VAT and without, Packaging) - F:Q
Additional Info (Manufacturer, Supplier, et.c) - Column R, S and next ones
From time to time for example as it is visible in the Row 7, I need MAX PRICE for all the same products.
I achieved that with formulas:
Picture: F7
Picture: N7
These two formulas work and does everything I need. So no problem here.
THE PROBLEM
The Problem sits in R7 and S7 (I highlighted them in picture named "Sheet Document").
I found formula that works:
=SUBSTITUTE(textjoin(", ",true,unique(filter(R4:R,$C$4:$C=$C7))),", 0","")
It combines all unique Column R values that mathces all the C7 values.
This is how formula should look like.
Picture How it should be
Problema is - it works only with Iterative Calculation - ON.
Why it is a problem?
Each time I want to add this formula to another cell (I'm planning to add it manually, because there are specific instances where I need to know combined info about the specific product), it duplicates everything (See GIF below) ↓
GIF: GIF - Problem - Duplicating
I think it is because of Iterative Calculation, I have never seen any formula act this way before.
What can be done here?
Maybe use other formula for R7, S7?
I have tried a lot of - Vlookup, Index-Match, Query, the only one that worked exactly as I wanted was Substitude-Textjoin-Filter, but yeah, Iterative Calculation meses it up.
Maybe I need to change all the other formulas?
I know that with the Circular Dependency Error, you should look for overlapping formulas. In the OVERALL EXPLANATION section you can see how other formulas in the same row are made. I couldn't figure out the one that was overlapping.
Maybe some App Script can solve this?
I'm very new to scripts, have used in some documents, including this one, I am open to using them, just need little bit more explanation.
I tried a lot of different formulas, tried to solve Iterative Calculation glitch, changing formulas in other cells so they are not overlapping.

Use a mix of absolute and relative references, like this:
=textjoin(", ", true, unique( filter(R$4:R6, C$4:C6 = C7) ) )
The formula should go into cell R7. You should turn off iterative calculation if you can.

Related

Is there any way to make it so that a cell can only be changed once in Google Sheets?

I have a Sheet which I would like to use as a simultaneous sign up for many people for timeslots for an event. We have noticed that what can happen is users erasing each other's entries in the sheet. Ideally we would like to make it so once someones name is entered for a timeslot it cannot be removed by other users.
I've tried to use data validation to reject certain criteria, but I've only managed to get it to reject a cell changing from blank to a non-blank value. Which I achieved with the following:enter image description here. But I'd like the opposite behaviour, with some additional functionality
Changing the formula to NOT(ISBLANK(B2)) doesn't seem to put any restriction on the cell at all as hitting backspace or delete on cell seems to clear the contents without ever considering that an input to check. Changing the value never causes the cell to go blank so it doesn't seem to affect changing either. I'm really at a loss as to how to do this and any help is appreciated. I'm open to solutions which use VBA or other programming languages to get the desired result as well.

Chart text responses in a google spreadsheet

I have a google form that has the following multiple choice question:
How would you rate your general well-being today?
-Very well
-Slightly less than par
-Poor
-Very poor
-Terrible
The form then saves to a google sheet. A column of this data might look like this:
How would you rate your general well-being today?
Slightly less than par
Very well
Very well
Very well
Very well
Slightly less than par
Very well
Where the question is in the top row...and each subsequent row is the a day of the week (and how the person was feeling that day).
I am wanting to view this data in a chart (pie or bar); but am not sure how to handle it since its text and not numbers. One way I was considering is the add some sort of function to the cell that would convert the response to an integer so it could be charted. So in the case of this question the scale would be 1-5; 1 being Very Well and 5 being Terrible. Feels kind of janky, but wanted to check and see if there is an easier way. The once I had a text respesnetation of the responses I could easilty put a chart on them.
Here is what I ended up doing.
In a separate column I have the following function:
=SWITCH(K2,"Very well",0,"Slightly less than par",1,"Poor",2,"Very poor",3,"Terrible",4)
Where column K2 contains the users response. I copied this function to all rows in this column, so now I have numbers 1-5 to represent the users response. Now just highlight the column and add the date on the X-axis and it gives me a nice chart like this:
Might be nice to have the labels rather than numbers on the left side if anyone has suggestions on that.

Intelligently Fill Down Custom Function With Range Parameter in Google Sheets

I have a range of cells that come color coded (background color) from another system (that exports its data into excel format, which I have imported into Google Spreadsheets/Sheets) and I need to make simple calculations based on the background color of each cell.
Unfortunately, the only way I've found in Sheets to determine the background color of a cell is through the use of a script, which I have no experience with.
I have been using the following script:
function getBGColor(range) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
return sheet.getRange(range).getBackgroundColor();
}
My issue is that the range must be entered in quotes. My understanding is that the value of the cell is passed to the function if the range is entered without quotes. Correct?
=getBGColor("E2")
Sheets doesn't intelligently fill down values in quotes. When I fill down, the formula does not increment as I would need it to (there are hundred of cells I need to get the color of).
I get
=getBGColor("E2")
=getBGColor("E2")
instead of
=getBGColor("E3")
=getBGColor("E4")
I feel like I must be searching using the wrong terminology because I can't find any solutions to this. Do I need to create a custom function that replicates the intelligent fill-down functionality or is there some other solution that I've missed somewhere? Am I attacking the problem incorrectly?
I try to make sheets that I can re-use when new data is available and that can be manipulated on the fly (lots of cell references) to demonstrate the effects of changes in data but it is looking like Sheets may not be the best tool for this? Excel has worked well but my superiors are pushing to move all of this kind of data into Sheets.
Thank you.
Just found something that seems to work. While the
CELL("color",reference)
doesn't work, it did lead me to the address info_type. I was able to use the following workaround:
=getBGColor(CELL("address",E2))
which will intelligently fill down.
If there are better ways to do this please let me know!

How to do page wise subtotal in google spread sheet

I am in need of creating pagewise subtotal (page wise running total) in a google spread sheet. This mean in each page (Letter-size) I need to sum a field and display. I see that spread sheet puts header & page numbers in each page. Is there a way that I can have this value too. After looking at the documentations and search I found the Spread Sheet doesn't have page break. Also tried to calculate the row heights and break the page by adding my sum and page numbers. That is not always reliable and messy.
As you noticed, Google Spreadsheets don't know anything about pages... Pages are created at export / printing time which is 'too late' for what you need to do.
The closest solution I can imagine would be to export a number of rows + the subtotal as a table into a Google document, the latter having page numbers, footers and headers to customize their layout in a proper way.
You will loose the spreadsheet features on your way but I don't know if that would be an issue for you.
You'll also loose part of the formatting (if you added some in the SS) but that should be more or less re-doable from within the text document.

setNumberFormats not working properly for percentages

I have a Google spreadsheet in which I want to copy values from one range into another range using a script. Copying the values isn't hard; I just use range.setValues(valuesToCopy). I also want to copy the formatting of the original range over to the new range. The problem is that whenever a percentage occurs, it doesn't apply the format correctly and always ends up off by a factor of 100. For example, if the original cell contains a value of 0.5545, the formatting of the cell turns it into 55.45% (which is what I want); however, when I copy the values to another range and apply the formatting with setNumberFormats(), it turns it into 0.5545%. How can I fix this?
EDIT: So, after a bit more fiddling around, it appears that my script properly copies the formatting over the first time, but on subsequent executions of the script, the formatting for the percentages gets messed up, as explained above.
To copy values, use the .copyTo method, and the format is preserved by default. For example,
rangeFrom.copyTo(rangeTo)