script for IF Else statement to put commentary for variance of actual vs budget - function

Can anyone please help me to write an IF else script in google app script?
the logic is:
I have 6 separate business unit tabs and in every tab in column M row 8 we have to force them to put commentary based on:
if actual in column J row 8 is less than the budget column H row 8, then M8 should display as Reason for variance: and actions to improve:
If f actual in column J row 8 is more than the budget column H row 8, then M8 should display as Reason for variance: and how to maintain:
If f actual in column J row 8 is equal to the budget column H row 8, then M8 should display as Any Comments (Optional):
Can someone please help how to write this script?
I tried but couldnt set the logic yet.

Related

Possible to filter SUMIF results based on if cells within a range match a specific cell?

I'm trying to automate my time tracking a bit more, and making it a bit more thorough.
Here's a link to my example that I'm working on
Basically, I want to add values in another tab based on the selection in the drop down menu, but filtered by specific weeks of the year.
Explanation:
In the C or D column of tab "Top 2023", calculate minutes based on the minutes in column G and the drop down in column C tab "2023"
Currently, I have that part working. I used SUMIF to look at column C on tab "2023", check if it matches "Work" (or "Off"), then add the hours based on either criteria.
I want to then filter that data based on the week of the year, listed in columns A in both tabs
I want to automate this so I don't need to touch it or manually select what rows are included, only to move the formula down. So if 3 rows on tab "2023" show week 1 in column A, then they're all added to C2 and D2 on tab "Top 2023", so on for the rest of the weeks of the year.
Is this possible? I was playing around with a few formulas trying to make it work (I'm still learning and researching!) in column F on the "Top 2023" tab, but couldn't quite figure it out.
I tried:
My formula to calculate the hours from tab "2023" to tab "Top 2023" is =SUMIF('2023'!C3:C,"Work",'2023'!G3:G) which works fine.
I understand doing G3:G is going to grab the whole column, so I want to filter it down further without having to manually update the G3:G portion every week.
I tried this (I know it doesn't work, and I'm having hard time understanding if it will work): =ArrayFormula(sumifs('2023'!C3:C,"Work",'2023'!G3:G)(FILTER('2023'!A3:A)A2))
Which of course brings back an error, because it doesn't work like that.
this is single cell formula + drag-down and goes in cell C2:
=SUMIFS('2023'!G3:G,'2023'!C3:C,"Work",INDEX(WEEKNUM('2023'!B3:B)),WEEKNUM(B2),INDEX(YEAR('2023'!B3:B)),YEAR(B2))
this is arrayformula within C2 (auto-applies to whole column C):
=BYROW(B2:B,LAMBDA(bx,IF(bx="",,SUM(IFERROR(FILTER('2023'!G:G,'2023'!C:C="Work",WEEKNUM('2023'!B:B)=WEEKNUM(bx),YEAR('2023'!B:B)=YEAR(bx)))))))
change 'Work' to 'Off' within the formula for Colum D (time off) values
also took into account direct 'Date' Columns in both tabs instead of
the helper columns created exclusively to extract WeekNumber.

How to compare one row of data to every row of data from another table in google sheet?

Hi everyone,
I need some helps on this task.
My goal is to determine whether the Status in Column I is accepted or not. If it is accepted, then print Accept in Column I and print the Actual Time Accept in Column J based on Actual Time in Column C , otherwise just leave it blank.
Rules to determine the Status(Accept):
Forecast Time in Input greater than Time in Output
The Price in Column G is greater than the Actual Price in Column D.
Once these 2 rules are fulfilled, then print Accept in Column I and print the Actual Time Accept in Column J based on Actual Time in Column C , otherwise just leave it blank.
As you can see from my formula in cell I3, it only compare row by row (one row in Output compare to one row in input).
What I want is comparing one row of data in Output to all the rows in Input to determine whether the Status is accepted or not.
Example
For example, the 1st row in Output, the Time is 16:16:41. We compare this Time with the Forecast Time in Input. The formula start to compare from the row with Forecast Time 16:17:43 since the Forecast Time in previous rows are all smaller than 16:16:41. Since 16:17:43 greater than 16:16:41, it fulfilled the first rules. However, the Price in Output, 216.5 is smaller than the Actual Price in Input, 216.56, so the Status will still be blank. The formula will move on to the next row and check the rules again.
Since the next Forecast Time, 16:18:02 is greater than 16:16:41 and the Price in Output is 216.5 greater than 216.48, all the rules fulfilled, so the Status will be Accept and the Actual Time Accept will be 21:34:00
The link for google sheet is here in case is needed:
https://docs.google.com/spreadsheets/d/17coke3-oyDRLHgz79PDl3KX68kFOEte-aynVe-xEITU/edit?usp=sharing
Please give me some advice on this problem, I'm not sure this can be done without using Google Apps Script. Please let me know if you are not clear on what I'm asking about, any help will be greatly appreciated! Thank you.
I3 & drag down:
=IF(J3="",,"Accept")
J3 & drag down:
=IFNA(INDEX(FILTER(C$3:C, D$3:D<G3, B$3:B>H3), 1))

finding the max value of every 24 rows in a matrix of a certain column

I have imported a huge excel file into matlab. The file is a database with 5 columns and 175000 rows. I want the maximum value of every 24 rows of the third column.
can anyone help me plz?
I hope I got what you want right,
I believe you can do something like this:
(forgive me I'm not writing matlab coding)
col = 3
for i = 1 to number_of_rows
Add the element at (i, col) to a new array
i=i+23
end for
then fine the maximum value in the new array you created in the loop, hope this helps

google spreadsheet query function: Extrange behavoir with columns with different types of cells

I use the new google spreadsheet and I detect an extrange behavior when a column has different types (number and string) and has automatic format option. Some cells disappear from the result.
Ej.:
11 z
22 z
11 z
xx z
yy z
Result of =query(A1:B5;"select *"):
11 z
22 z
11 z
z
z
Result of =query(A1:B5;"select A, count(B) group by A"):
count
2
11 2
22 1
It's clear that when the column has a string format, it works.
But sometimes, when I use results of the forms to summarise data, the new entry doesn't respect the column format (as previous spreadsheet version it does), so the spreedsheet try to convert to a number the form entry if it is possible. Thus, I have a string and number data in the same column.
Does anyone know how to make the 'query' function to work properly, regardless of the data type of the cell in a column?
Thanks in advance.
According to AD:AM May 10, 2012:
Unfortunately it's just a limitation with QUERY, Marinus, that it will only "accept" one data type per field.

including a conditional statement in a =QUERY function

How can I add a conditional statement (similar to an 'if elseif' in .php) to the query listed below so that it will return columns D and E from Sheet2 if column C in the responses sheet == 1st, or columns F and G from Sheet2 if column C in the responses sheet == 2nd? It must still only return column data from the appropriate row (based on the query).
=QUERY(Sheet2!$A$1:K; CONCATENATE("SELECT B, C WHERE A = ", responses!B1), 0)
I looked into IF(OR), but I don't believe that will work because final project will have more than two possibilities (there will actually be eight, 1st through 8th class period).
Here is a link to the Google Spreadsheet I'm working with
Any suggestions?
Thank you for your time and assistance,
Todd
High School Teacher
That cant be done with query. All rows must select the same columns.
Use a formula post-query (like an arrayformula)