Formula to SUM cells to the left? - google-sheets

I need a Sheets formula for a Year to Date field. Essentially, I need to sum up the cells to the left of a given cell, up and to the 11 previous cells (there are multiple years in a single row). In Excel, this is accomplished via OFFSET and a -Width value. Sheets won't play nice with -Width.
Does anyone have any suggestions?
For what it's worth, the formula that doesn't work in Sheets (but does in Excel) is as follows:
=SUM(OFFSET(Forecast!$B$12,ROW($A13)-ROW($A$12),MATCH(Report!$I$1,Months,0)+2,1,-$I$2))
Where -$I$2 is a variable number of months field.

I used indirect and the RC format. This secret sauce is the max(COLUMN()-11,1).
=sum(INDIRECT("R"&row()&"C"&max(COLUMN()-11,1)&":R"&row()&"C"&(COLUMN()-1), FALSE))
or with your $I$2 cell
=sum(INDIRECT("R"&row()&"C"&max($I$2-11,1)&":R"&row()&"C"&($I$2-1), FALSE))
Edit:
With the additional info, assuming your entry is in br, your first month is in bc, the sheet your interested in is sh and you want to go back $I$2-1 columns (because bc counts as one)
=SUM(INDIRECT("sh!"&"R"&br&"C"&(bc+1-$I$2)&":R"&br&"C"&bc,false))

Related

Google Sheets formula recalculation quirk

This may simply be a convoluted duplicate of an existing question, and I have been able to find one or two issues that match what I'm seeing here, but I am very curious to see if the cause is just user error on my part or if this is something I am just not aware of.
I have a worksheet titled Sheet1 with 999 rows. On this sheet in cells A3, B3, and C3 down are Year values (2021), Month numbers (1, 2, 3, etc.), and Quarter (Q1, Q2, etc.). In cell D, I have the following long but simple formula:
=SUMPRODUCT((MONTH(INDIRECT("TestSheet ("&C2&" "&A2&")!$C$3:$C$999"))=B2)*(YEAR(INDIRECT("TestSheet ("&C2&" "&A2&")!$C$3:$C$999"))=A2)*(INDIRECT("TestSheet ("&C2&" "&A2&")!$E$3:$E$999")))
What this formula does is sum the monetary values from sheets with variable names by month (INDIRECT is used to refer to sheets with the name "TestSheet (x y)", where x is the Quarter value and y is the year (ie: "TestSheet (Q1 2021)").
This formula functions as intended, and correctly sums the values on the variable sheet names when those sheets exist. The issue I'm running into is that it seems to take a length of time for Sheets to identify that a sheet exists, even when "On change and every minute" is selected under the Calculation tab under Spreadsheet Settings. From testing on a fresh workbook in which this formula is the only one present and there are no other formulas present that could be slowing down the recalculation, the cell values do not appear to update at all even an hour after the relevant cells have been updated with data.
Is there any indication based on what I have so far that stands out as a possible cause? Any suggestions would be appreciated.
try:
=INDEX(SUMIF(TEXT(
INDIRECT("TestSheet ("&C5&" "&A5&")!C2:C"), "yyyyM"), A5&B5,
INDIRECT("TestSheet ("&C5&" "&A5&")!E2:E")))

Google Sheets Hyperlink to Dynamic Field Within a Given Sheet

I have a Google Sheets document with a series of fields for every day in the year. The top row (Actually, row 2) is the Months (by full name, eg. January, February, etc.). The A column is numeric, from 1 to 31. There are several fields for each date, so the fields in the A column are merged (in other words, it's not A2, A3, A4 - more like, A2, A7, A12).
What I'd like to do is put a a hyperlink at, say, B1, that points to "today's" top field. So, today's would point to J7, and I could just click the link at B1, and get taken directly to that field.
I know this is going to involve the HYPERLINK function, but I can't figure out how to get it to work. Something like:
=HYPERLINK("#gid=0&#range=" & MATCH(TEXT(TODAY(),"MMMM"),2:2,0) & MATCH(DAY(TODAY()),A:A,1),"Click for today")
But I can't get it to work right. Any thoughts?
Assuming your months are in every column from B2:M2:
=HYPERLINK("#gid=*000000000*&range="&ADDRESS(MATCH(DAY(TODAY()),A2:A,1)+1,MONTH(TODAY())+1,4),"Click for today")
I wrote the formula so that the link could go in A1 without running into trouble, if you like. (It would also work in B1, etc.)
If there are spaces between your months, just reorder what you had so the MATCH for the row is first and wrap it in ADDRESS( row, column, 4):
=HYPERLINK("#gid=*000000000*&range="&ADDRESS(MATCH(DAY(TODAY()),A2:A,1)+1,MATCH(TEXT(TODAY(),"MMMM"),2:2,0),4),"Click for today")
(To be clear for future users, you'd need to replace the gid= number with the actual number corresponding to your sheet.)
Eric Tyler - Close. But it got me where I needed to be, so thank you so much. I was missing two key funtions: ADDRESS, and SUBSTITUTE. Here's what wound up working. (Note: In my case, the gid is 0.)
=HYPERLINK("#gid=0&#range="&SUBSTITUTE(ADDRESS(MATCH(DAY(TODAY()),A:A,1),MATCH(TEXT(TODAY(),"MMMM"),1:1,0)),"$",""),"Click here")
The ADDRESS line the way you proposed it results in the address in the format $A$1, which the HYPERLINK function doesn't like. Using that just brought be to the sheet, but not the actual cell. By using SUBSTITUTE to get rid of the $ marks, that resolved the problem.)
Thanks again!

Google Sheet SUMIF not summing range

I am trying to SUM all rows based on the condition that a row's value is greater than 0. However, the formula is only calculating the first row and ignoring the rest of the range. I encountered this issue on a different spreadsheet but I isolated the issue on a new spreadsheet to show you and ask questions.
The answers should be B1 ($5), B2 ($15), B3 ($30).
I followed the formula's usage as explained in the Google Docs https://support.google.com/docs/answer/3093583?hl=en
The formula with respective row number =SUMIF(A1, ">0", A$1:A1)
Update - The below is my intended purpose. I have a spreadsheet that calculates money In and Out. For each of these transactions, I simply want the balance as a result of such transactions. This only works for the first row. (I hardcoded the values for the rest of the rows just to show my goal.)
try:
=ARRAYFORMULA(IF(A:A="",,SUMIF(ROW(A:A), "<="&ROW(A:A), A:A)))
if you prefer dragging do:
=SUMIF(INDIRECT("A1:A"&ROW()), ">0")
UPDATE:
=ARRAYFORMULA(IF(D2:D="",,
SUMIF(ROW(D2:D), "<="&ROW(D2:D), D2:D)-
SUMIF(ROW(E2:E), "<="&ROW(E2:E), E2:E)))

Is there a function that can create an expanding array formula that conditionally sums a column based on multiple criteria?

To start, this is my first time posting and so please let me know if I can fix my post in any way to make it easier to answer.
I am trying to create an auto-expanding array formula
I have a sheet with my investment asset mix that including amounts of shares owned of each particular stock, and a sheet that tracks when I receive dividends. My goal is to write an automatically expanding array formula that will sum up the amount of shares that own of a stock on the date a dividend is received and return that value. I have written three different formulas that all accomplish this but none of them will auto-expand as an array.
I'm sure there are a lot of solutions I've overlooked. To boil it down, I need an expanding array formula that will sum the "Shares" column of my asset mix sheet ('Asset Mix'!D2:D, or 'AssetMixShares') conditionally. The name of the stock entered in 'Dividends'!C2:C needs to match the name of the stock in 'Asset Mix'!A2:A (or the named range 'AssetMixStocks'). It then needs to check the dates in 'Asset Mix'!C2:C (or 'AssetMixDates') against the dates in 'Dividends'!A2:A and sum all share amounts where the purchase date is less than (earlier than) the Ex-Dividend Date.
I could probably write some sort of vlookup array on the "Running Total" column -- 'Asset Mix'!E:E -- that would solve the issue, but I'm hoping to eliminate that column. I feel very strongly that what I'm trying to do should be possible without the help of a running total column -- I just don't have the knowledge.
I have tried countless functions and formulas, but the four that I currently have in my example worksheet are SUM, SUMPRODUCT, DSUM, and QUERY.
Attempt 1
SUM and IF
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Attempt 2
SUMPRODUCT
=({arrayformula(SUMPRODUCT(--((AssetMixStock=(indirect("C"&ROW())))*(AssetMixDate<(indirect("A"&ROW())))),AssetMixShares))})
Attempt 3
DSUM
=DSUM('Asset Mix'!A:E,"Shares",{"Date","Stock";"<"&A2,C2})
Attempt 4
QUERY
=arrayformula(query(AssetMix,"Select sum(D) where A = '"&C2:C&"' and C < date'"&(text(year(A2:A),"0000") & "-" & text(month(A2:A),"00") & "-" & text(day(A2:A),"00"))&"' label sum(D) ''",0))
These will all work, as long as I manually drag the formula down, but I want to write some sort of formula that will auto-expand to the bottom of the Dividends sheet.
I have tried to create a Dummy sheet that has both of the relevant sheets. Please let me know if you can access it -- the link is below.
https://docs.google.com/spreadsheets/d/1wlKffma0NJ0KrlWxyX_N20y62azsGpFp3enhmjzJK1Q/edit?usp=sharing
Thanks so much for getting this far and any help you can provide!
We can focus in the first formula to understand a way to make it "self-expandable". As we see it contains references to the cells A2 and C2 in "Dividends" sheet:
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Every time some data appears in these columns (A and C), the formula should work. We can control the presence of the formula by onEdit trigger, if editing is manual. Consider the code:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
if (sheet.getName() == 'Dividends') {
var row = e.range.getRow();
for (var offset = 0; offset < e.range.getHeight(); offset++) {
sheet.getRange(3, 10).copyTo(sheet.getRange(row + offset, 10));
}
}
}
It checks any modification on the sheet "Dividends" and copies required formula to the modified row(s). This way the formula is expanded for other rows in use.
Well, it's solved! I'll leave this up in case anyone else has the same question.
A kind soul explained the magic of MMULT() to me, and wrote this solution.
=ARRAYFORMULA(MMULT((C2:C=TRANSPOSE('Asset Mix'!A2:A))*(A2:A>TRANSPOSE('Asset Mix'!C2:C)),N('Asset Mix'!D2:D))

Any way to highlight current date column in my google spreadsheet?

I have this planning sheet I am working on: https://docs.google.com/spreadsheets/d/1GQpZh0MOotBl_iAucGm_LnK8shIKjjgukGqaFVvGKF8/edit?usp=sharing
As you can see events are planned out on a sort of calendar look.
I will be using this every day and I would like it to highlight the current date to me automatically. I've highlighted today's date manually.
Do you see any way to do this?
It does not need to be the whole column it can just be the day number and week of day on the top if it's easier.
I would greatly appreciate any help you can give me regarding this!
Thanks a lot.
Balint
I found this question when searching for a way to highlight a whole column/row.
Here's the way to do it:
Apply to range: A1:Z1000 (this is the range of all columns/rows including the dates)
Format cells if...: [Custom formula is]
Formula (for columns): =A$1=TODAY()
Formula (for rows): =$A1=TODAY()
The dollar sign ($) will keep the reference cell fixed. So if the formula uses A$1 it takes A1, B1, C1 etc to look for the date and then highlights the entire column A, B, C etc.
If the formula uses $A1 it takes A1, A2, A3 etc to look for the date and then highlights the entire row 1, 2, 3 etc.
Just make sure that "range" covers the entire rectangle of cells and not just one date. It's easy to adapt if your dates are in a different row/column.
Hope this helps the next person who comes here with a similar problem :)
You would have to use conditional formatting
on the column with the dates. Rule should be "Date is today". Choose a color to your likings.

Resources