How to know the "position" of a number in an "array"? - google-sheets

I'm having kind of a problem to make this question since I don't know if the terms that I'm using are correct, so bear in mind that maybe they aren't, so "array" and "position" maybe aren't what I mean. I worked a lot on the explanation, trying to make as simple as possible, I really hope it's helpful.
I have a Google Spreadsheet with twenty three sheets. All of them are related to a specific season of the Barclays Premier League and one is for calculation purposes.
I'm calculating now how high in the attacking ranks, a team that had the 10th best defense was. It looks like this:
1 A | B | C | D |
2 Season | 10th Defense (Goals Conceded) | Finished Position | Attack Position |
3 1992-93 | 55 | 5 | ? |
My problem is that unlike B3, where I get the quantity of the goals conceded, in D3 I don't want the same thing. What I'm trying to do is it to get the "array" of goals by each team in '1992-93'!G1:G23 and it to tell me where their attack finished (1st, 2nd, etc). So it needs to get the position of the team in C3 to know which attack belonged to the team and them look on '1992-93'!G1:G23 to know the position of the attack.

You want RANK and INDEX.
RANK(INDEX('1992-93'!G1:G23,C3),'1992-93'!G1:G23)

Related

Is there a way to remove 2 letters from a cell with a string (if they exist), and add a symbol on the end of the string?

I'm trying to code a google sheet to help develop a system to keep track of what training different people have. This is for an online role-playing game, to keep track of what spells/abilities different people have learnt. We've assigned different trainings a letter in the alphabet for ease of use. When someone has multiple trainings under a certain category, I want these to be able to combine to give a symbol rather than a letter. For example, if "A" and "T" are both related, I want them to be able to combine to give the "#" symbol.
It's a strange concept, I know, but this is the way our system has been built. I want to be able to have all people in the tracker sheet, then on a separate sheet, I want to be able to type their name in, and it will spit out their compressed training history.
The sheet's columns are formatted like so:
1. | A | B | C | D | E | F |... (Column)
2. |Name | Position | A | B | C | D |... (Header)
3. |John | Wizard | T | F | T | T |... (Data)
I've set up the main sheet, so that when I type their name, it uses the formula:
=JOIN("",
ARRAYFORMULA(
IF(
INDEX(Tracker!C:AB,MATCH(A2,Tracker!A:A,0),Tracker!C:AB),Tracker!C1:AB1,
)))
I've tried using regex extract/replace, however I'm not too good with regex, and I only want to replace characters with a symbol if BOTH exist, otherwise just leave it.
https://docs.google.com/spreadsheets/d/1cYGgmFJGGMtmwy6LF5k91H3-6UBVYIH_n8TIn1TU1Cw/edit?usp=sharing
Up there is a link to a sheet I just made, showing what I want to do. If anyone has suggestions, or questions, feel free to leave them here, or comment it on the spreadsheet.
Thank you in advance for any responses.
You may try below formula-
=REGEXREPLACE(JOIN("",FILTER(Tracker!C1:AB1,INDEX(Tracker!C2:AB,MATCH(A2,Tracker!A2:A,0)))),"[AT]","")&"#"
Here INDEX()/MATCH() will detect and return row based on name.
FILTER() will return characters based on selection of checkboxes of person row.
JOIN() will concat all characters in a single string.
Finally REGEXREPLACE(#,"[AT]","") will remove A & T.

Is it possible to aggregate expenses per category in google spreadsheets

I am trying to track my expenses manually. I looked for already built options and I did not find anyone I knew how to use or that it covered what I want to do.
What I am doing is basically manually write down what appears in my bank, with the intention of categorizing the expenses myself, since as I said, I did not find a better way to do it.
So it looks like this:
Cinema | 11.95
Going out (restaurant1) | 26.55
Netflix | 13.95
Weekly purchases | 72.66
Going out | 9
Bill (type) | 29.16
Rent month | 650
Going out | 26.55
Bill (type2) | 66.45
Compra semanal | 81.09
Bill (type3) | 21.1
( "|" is used as if it were two different cells) And what I would like now is to take the generic name that I gave the cathegory (without the parenthesis, I am using those for myself, so I can track where was the money spent, more specifically), and how much was spent.
In programming I would do this with a regex for the left cell, and aggregating by name, and then plotting the data somehow. I am unsure if this is even possible, maybe I should use Excel but Drive has the cloud advantage so I would like some help as to where to start, I do not need anything too fancy, a new column with the category and the total spent would work wonders for me, but I have not found an easy way of doing it (and I doubt I am doing something so complex, so I assume I am thinking this the wrong way). Best case scenario, I manage to plot it all so it is more visual, or I can have several columns plotted against each other (I have different columns for shared expenses, personal expenses, and so on).
If you can put the category (e.g. Bill) in a separate column from your details (e.g. type 1) then the Pivot Table feature is exactly what you need.
Start with something like this (the heading on each column is important):
Category | Details | Amount
Cinema | | 11.95
Going out | restaurant 1 | 26.55
Netflix | | 13.95
Weekly purchases | | 72.66
Going out | | 9
Bill | type | 29.16
Rent month | | 650
Going out | | 26.55
Bill | type2 | 66.45
Compra semanal | | 81.09
Bill | type3 | 21.1
Then click Data, Pivot Table. Under Rows, click Add and choose Category. Under Values, click Add and choose Amount. You should see a table like this:
Category | SUM of Amount
Bill| 116.71
Cinema | 11.95
Compra semanal | 81.09
Going out | 62.1
Netflix | 13.95
Rent month | 650
Weekly purchases | 72.66
Grand Total | 1008.46
Any unique value in the Category column creates a new row in the pivot table.
Further Details: https://support.google.com/docs/answer/1272900
=ARRAYFORMULA(QUERY({REGEXREPLACE(TRIM(A:A)," \(.*\)",),B:B},"Select Col1,sum(Col2) where Col1 is not null group by Col1"))

Google Sheets Function to get value of adjacent cell based on key

I need some help figuring out some Google Sheets function. I'm trying to look for the value of an adjacent cell based on a key. The problem is that the table has several rows and columns to search for. For example:
| A | B | C | D |
1 | Alpha | 5 | Bravo | 10 |
2 | Charlie | 15 | Delta | 20 |
The list goes on for several more rows and colums. What I'm looking for for example, is when a search use "Delta" as my search key, it will return the value 20 for me. I appreciate your help. Thanks!
Here is the answer I got on the web application community:
https://webapps.stackexchange.com/questions/90198/how-to-get-value-of-adjacent-cell-based-on-key-if-the-table-is-split-into-multi
You can still use vlookup for this, by stacking the lookup tables into one using the array notation {first ; second; third} which means first above second above third. Example:
=vlookup("Delta", {A:B; C:D}, 2, False)
returns 20.
Try:
=offset(lookup("Delta",A1:D2),0,1)
You could use the following:
=ArrayFormula(INDEX($A$1:$D$2,MIN(IF($A$1:$D$2=$G$1,ROW($A$1:$D$2))),MIN(IF($A$1:$D$2=$G$1,COLUMN($A$1:$D$2)))+1))
This could by done in several ways.
Use RegEx
=regexextract(CONCATENATE(A1:D),F6 & "(\d+)")
where F6 is cell with lookup value i.e. "Delta"
Use lookup
=INDEX(A:D,MATCH(LOOKUP(F6,A1:D,A1:A),A1:A),MATCH(F6,INDIRECT(MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)&":"&MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)))+1)
where F6 is cell with lookup value i.e. "Delta", look at example.
MATCH(LOOKUP(F6,A1:D,A1:A),A1:A) is used 3 times, so it could be counted in separate cell.

Dealing with multiple strings and corresponding integers in a single cell

I’ve got a question about something I’m trying to achieve in Google spreadsheets. I’ve got the following table:
| NAME | COUNTRY |
--------------------------------------------------
| Alpha | GER*1, SWE*3 |
--------------------------------------------------
| Beta | GER*5, SWE*1 |
--------------------------------------------------
| Gamma | SWE*5, GER*3 |
--------------------------------------------------
| Delta | SWE*2, GER*1 |
--------------------------------------------------
Now I’d like to be able to calculate how many SWE there are in line Gamma. I’d need spreadsheets to return an integer value, in my example the correct one would be 5.
However, I’d also like to be able to calculate the total number of GER in line Alpha to Delta, also returned as an integer value, in this case the result should be 1+5+3+1 = 10.
As you can see I’m dealing with both strings and integers in a single cell. If it would be possible to for example create an array of all GER*(INTEGER), then delete the GER* and have an array of only the integers that might help me?
I’ve searched here, googled around and fiddled with spreadsheets to try and come to a solution but either I’m too daft or it’s not as trivial as I thought it’d be. Any help would be much appreciated.
To calculate the total number of GER in line Alpha to Delta (assuming your data extends from row 2 to row 5) , try:
=sum(ArrayFormula(iferror(regexextract(B2:B5, "GER\*(\d+)")+0,0)))
To calculate how many SWE there are in line Gamma, try:
=sum(ArrayFormula(iferror(regexextract(filter(B2:B6, A2:A6="Gamma"), "SWE\*(\d+)")+0,0)))
Change the ranges so that they suit your actual data range and see if that works ?
You could use one of the Text functions, like FIND together with MID. REGEXEXTRACT is even more powerful but harder to use. When you have the substring, use VALUE to get the numeric value from it.
For the summary, the easiest is probably to create an extra column, extract the GER value into it as above, and SUM that column.
Here's the function reference for Google Spreadsheets: https://support.google.com/docs/table/25273?hl=en

How to get the data for the next two weeks?

I've several straight-forward planners, like this:
| date | person | person 2 | description |
2013-03-01 peter pam painting
2013-03-18 john carl cleaning
2013-03-20 max anne washing
On a different sheet, I want to filter the 'events' for the next 2 weeks only. How can I achieve this? I tried several ways, but none of them are working.
With =ARRAYFORMULA(DAYS360(B2:B;NOW())) I can get a daynumber in a different column. 0 = today, 1 = yesterday, -1 tomorrow et cetera. In fact, I need to filter the days -1 to -14. Sometimes there are only 2 events, sometimes 5 in 2 weeks.
Edit: Some things I found
First, I filter the correct daynumbers with =filter(A2:A50;A2:A50>-14;A2:A50<0)
Then, I do a vlookup =vlookup(G32,A1:E49;5;false)
(where G32 is the filtercommand, A2:A50 the daynumbers, A1:E49 all the data)
This is a good opportunity for the QUERY command and Query Language.
I'm assuming your data is in 4 columns, A:D, in "sheet 1".
=query('sheet 1'!A:D,"select * where datediff( A, now()) < 14 and datediff( A, now()) > 0")

Resources