Formula to Exclude Current Month - google-sheets

I am looking to find the average of a running list with values broken down by month.
The problem I'm having is excluding the current month from the formula.
I've tried using =indirect and =counta, but only got errors.
The closest I've been able to get is by using the sum and divide method, but it does not produce consistently accurate results.
https://docs.google.com/spreadsheets/d/1YH8vlvGAoZ9Z-uJTdesgmhX8t6pz3JoEhqi4t9-APSE/edit?usp=sharing
Any guidance is appreciated. The sheet is open for comments if it is easier to answer that way.

Its' a little more than what you're specifically asking here, but maybe this gets at what you're really going for. Take a look at a new tab called MK.help where you will find this single formula in cell A1 that populates the whole table.
=ARRAYFORMULA(QUERY({IFERROR(EOMONTH(Expenses!A:A,-1)+1),Expenses!B:C},"select Col1,AVG(Col2) where Col1<"&EOMONTH(TODAY(),-1)&" and Col1 is not null group by Col1 pivot Col3 label Col1'Month-Year'"))

Related

Stack Google Sheets columns in a cleaner way?

I am making a spreadsheet to compare various lists in various different ways. One of those ways is to take a bunch of separate lists (each in different columns) and combine them into one large column (without losing anything). This allows me to keep things separate while still having the option to VLOOKUP and FILTER and stuff. Maybe this isn't the way to go about it, but it's the way I've gone with so far.
The solution I came up with for now is to QUERY it all as an array (I think that's the right term) and then just select everything that isn't "".
It looks like this though:
=QUERY({Decklists!B8:B;Decklists!C8:C;Decklists!D8:D;Decklists!E8:E;Decklists!F8:F;Decklists!G8:G;Decklists!H8:H;Decklists!I8:I;Decklists!J8:J;Decklists!K8:K;Decklists!L8:L;Decklists!M8:M;Decklists!N8:N;Decklists!O8:O;Decklists!P8:P;Decklists!Q8:Q;Decklists!R8:R;Decklists!S8:S;Decklists!T8:T;Decklists!U8:U;Decklists!V8:V;Decklists!W8:W;Decklists!X8:X;Decklists!Y8:Y;Decklists!Z8:Z;Decklists!AA8:AA;Decklists!AB8:AB;Decklists!AC8:AC;Decklists!AD8:AD}, "select Col1 where Col1 <>''", 0)
Which is really ugly. It works and does what I want, but I'd much prefer it to be clean and work if I add more columns in the future, without having to go and add the additional "call".
If you'd like to look at the whole sheet, it's here: https://docs.google.com/spreadsheets/d/17Nwek5ZCgu7Jvk922hl_gv9UJAeORjeH9brXqu3zL_Y/edit#gid=940775206
On the "Best Buys" sheet cell C2 Paste this simple formula.
=QUERY(FLATTEN(Decklists!B8:AF), "select Col1 where Col1 <>''")
Explanation
1 - FLATTEN the range needed in this case the Decklists range Decklists!B8:AF.
2 - QUERY the resulted column from the FLATTEN function with the query "select Col1 where Col1 <>''", to get only non empty cells
Try
=query( flatten(offset(Decklists!A:A,0,1,,columns(Decklists!1:1)-1)) ,"where Col1 is not null",0)
So we have 3 things to do, first one is transpose so the columns are below the other, then flatten so that it is ordered as necessary and finally a filter to remove extra blank columns we selected This will work wonders considering the columns are different lengths, are already next to each other as in a table. If columns are at multiple places use {A:A;D:D} to select columns and remove flatten and transpose.
=filter(flatten(transpose(A1:D10)), len(flatten(transpose(A1:D10))))

Google sheets formula transposing column title to row

Attached is the link of my question
I would like to transpose the data like that.
My original data could be thousand of lines.
My thought is to make the same number of tables of my column title, then combine the four tables into one. My thought is on the google sheet as well. It might do the work but I would like a nicer solution.
A picture of my question
After having answered this question hundreds of times in the last couple years after the discovery of the FLATTEN() function, i decided to write a custom function for Google AppsScript to do it. While in some sense, a custom function is more opaque than the SPLIT(FLATTEN( formulaic solution you will find all over the forums in the last couple years, it is at least a little easier to understand in it's operation by the user.
In your shared sheet there is a new script file called MKHelp.gs. In it, you will find the code that I wrote to construct the "UNPIVOT()" function.
On a new tab in your sheet, you will find this formula in a tab called MK.Help.
=QUERY(UNPIVOT(A2:B,"V",C2:E,"B",C1:E1,"H"),"where Col3 is not null")
for unpivot to work well it is best surrounded by a query() to weed out unnecessary rows. In your case, it is that the "amount" not be "empty" or "null".
The letters "V","H" or "B" that follow each range describe the "shape" of the input data. Whether it is "vertical", "horizontal" or "Both".
Try
=query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")
Explanation
step1: =arrayformula(A3:A4&"♦"&B3:B4&"♦"&C3:E4)
step2: =arrayformula(flatten(A3:A4&"♦"&B3:B4&"♦"&C3:E4)) , flatten will put all data inside one single column flatten()
step3: =query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")

Run away rows in Google Sheets

Link to doc - https://docs.google.com/spreadsheets/d/1-kEMMiB6mj3lt3DUSDvW3BmdGaADajbGUwD_oZVllWU/edit?usp=sharing
I have written a formula that scans a list of Slack threads, formats the threads into plain text, then counts the frequency of every word in the range of plain text.
The goal behind this formula is to search for 'trending' keywords that frequently pop up in a Slack channel.
As you can see there are a couple tabs, the Readme does a decent job explaining everything but I'll give the TLDR here:
The Data tab contains all of the imported Slack information. Data!E2 contains a messy formula of REGEXREPLACE functions that filter the data into plain text.
In the Keywords tab under Keywords!A2 you'll find the 'frequency' counting formula. Here it is:
​=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(" ", Data!E3:E)," ")&{"";""}),"select Col1, count(Col2) where not(Col1 matches'"&JOIN("|", Stopwords!B1:B)&"') group by Col1 order by count(Col2) desc limit 800 ",0))
​To clarify the formula searches the range Data!E3:E and JOINS all the words together with a space delimiter. Then, we SPLIT the string across a number of cells and TRANSPOSE the new row of cells into a column of cells found in Keywords!A3.
Lastly, a query is run to count all of the instances of each word and places each keyword's count into Keywords!B3. One thing to keep in mind is this query is run against a list of stopwords found under Stopwords!B1 in order to remove a good deal of text from the query that would not really need to be counted.
As you can see I am now receive a #REF! error. This wasn't always the case, for a while this formula worked as expected, words were listed in column A under Keywords and column B showed the frequency they appear. The other columns then could run their functions off this list and fill in the rest of the Keywords sheet.
I am curious though, I noted when I set the function range to Data!E3:3000 that every time the function ran it would add another ten or so rows to the range, so it would grow to E3:3018, E3:3032 etc etc. Then it broke and now says "Error Result was not automatically expanded, please insert more rows (13)."
If anyone could help me optimize this formula to run a bit better that would be amazing. Thanks!
Sorry that no one has replied earlier. I just found this.
But I think your error is in column B of your Stopwords tab. The formula there should be moved to B1, instead of partway down the page. That is giving the REF! error, which then appears in your main formula when it references the Range B1:B.
Let me know if this helps.
And you may want to revise your formula to end with:
label count(Col2) ''
which removes the header for the count(Col2) column.

How to search and sort multiple columns into one column

This is like my input. if theres better way to import that site, you can suggest me it
I need to find all columns with prices and put them in one big column-table. My point is to use vlookup afterwards.
Also I need formula not normal references, because the table can vary. Similar thing is that there are always names+price(+$}.
It should maybe check every cell with text and check if theres number next to it, then add it to big table?
try:
=QUERY({
Original!D:E; Original!H:I; Original!L:M; Original!P:Q};
"where Col1 is not null and Col2 is not null"; 0)

How to use AVERAGEIFS within ARRAYFORMULA

I am trying to use AVERAGEIFS inside ARRAYFORMULA. Looking at other questions, I have come to the conclusion that it is not possible without using QUERY function.
My intention is to average the values of a column whenever they share the same ID.
I think this question comes pretty close to what I need, but I haven't been able to replicate and adapt its solution on my own sheet.
In this sheet I show the result I expect (I got it by dragging the formula). I've also reviewed the Query Language Reference, unsuccessfully.
Thanks a lot for your time and effort.
So the formula should be
=ArrayFormula(iferror(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)))
Note that if there were any text values in the points column, this would still return a result (because count would be greater than zero) - you could instead use
=ArrayFormula(if(isnumber(B2:B),(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)),""))
If you had a mixture of rows with text and rows with numbers for any ID, this would return a smaller result than the avg or average formula. This is a limitation of this method. You can't put an extra condition in (that column B has to contain a number) because you would need countifs and countifs isn't array-friendly. It still seems strange that AFAIK countif and sumif are the only functions out of this family that are array-friendly while countifs, sumifs, averageif etc. are not.
you can do:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A; QUERY(A2:B; "select A,avg(B) group by A"); 2; )))

Resources