Arrayformula for Index Match multiple columns with date values - google-sheets

I am collecting data on intervals and want to display a summary of that data on a single line in a new sheet.
https://docs.google.com/spreadsheets/d/1EOV4-VwVfwWvhwQ24qkQbCRGxUp74oe0dLWrbj0wiNE/edit#gid=566541214
Grade Data Sheet
Each batch of data comes in by date with a Name, Course and Grade like below
Raw data is like this for a large number of Name / Course / Grade:
Date
Name
Course
Grade
10/1/2022
Joe
Math
65-D
10/15/2022
Joe
Math
58-F
10/30/2022
Joe
Math
50-F
Summary Sheet
Single line that takes each unique Name-Course pair and I'm attempting to lookup a grade for each date column.
(note: I'm trying to extract the dates in the columns dynamically as the Grade Data sheet expands)
So I've successfully extracted the Dates to create new columns, and I am trying to create an index-match that grabs the column date and creates an array of DATE-NAME-COURSE and matches DATE-NAME-COURSE on the Grade Data sheet to return the grade for that student on the Date. The formula works for the first row, but when it fills down it returns the value of the first match.
I can't quite figure out how to reference the single date cell into the array while dynamically filling down. Not sure if I a different approach, but hopefully this makes sense.
=arrayformula(if(len($A2:$A),(index(GradeData!$D2:$D,match(TEXT(C$1,"yyyy-mm-dd")&$A2:$A&$B2:$B,TEXT(GradeData!$A2:$A,"yyyy-mm-dd")&GradeData!$B2:$B&GradeData!$C2:$C,0))),""))`
The goal is to have Grade Data populate automatically, and the Summary page to add a column for each new date and fill data down for each student.
Thanks in advance, I have shared the actual sheet above so you can see the data
I've attempted several different ways but can't quite get the dynamic array matches with the date formatting to work.
=arrayformula(if(len($A2:$A),(index(GradeData!$D2:$D,match(TEXT(C$1,"yyyy-mm-dd")&$A2:$A&$B2:$B,TEXT(GradeData!$A2:$A,"yyyy-mm-dd")&GradeData!$B2:$B&GradeData!$C2:$C,0))),""))
Thank you!

As far as I've seen the issue in your sheet is that the dates of the header do not match the dates of your source data. I've added a new header line:
=LAMBDA(dates,FILTER(dates,regexmatch(dates,"/")))(Transpose(Unique(arrayformula(left(GradeDataVlookup!A4:A,10)))))
And just put an IFERROR in order to avoid all the errors of the values without matches:
=arrayformula(if(len($A$2:$A),iferror(vlookup(TEXT(C$1,"MM/DD/YYYY")&$A2:$A&$B2:$B,GradeDataVlookup!$A:$E,5,FALSE),""),""))
PS: with MAP or MAKEARRAY you could summarize all the table in just one formula

Related

How to expand date ranges and unpivot data to create a lookup table

I have this sheet that includes a pivoted table with a range of months in columns and years in the header row and some values in the main table. I want to be able to expand the monthly dates along with the year, id, and values to more easily use it as a look up table to find valid user ids that have a greater value than the look up value for a given year. I provided a sample sheet with limited rows as an example. The row that is highlighted yellow (row 69) makes user 2 valid within year 2022. I would then conditionally highlight the valid user.
I can get the date ranges expanded but I have trouble keeping the other data matched up with the appropriate corresponding rows. I think it would be a fairly straightforward task with apps script but I am a very inexperienced user in that regard.
Here is my sample sheet: https://docs.google.com/spreadsheets/d/1bIji78wYu32O70C2xZLn8dntyYogs5ivuNvCFj5-Z0s/edit?usp=sharing

To find XIRR for different investments using google sheet

I am currently trying to calculate the XIRR of a huge portfolio containing non-periodic cashflows. The database contains lot of transactions and I want to calculate the XIRR for each one.
This image contains the format and the last column contains the TICKER names of firms. I want to calculate the XIRR for these firms. The database on the left contains all the data for the ticker names
Please find the sample sheet here:
https://docs.google.com/spreadsheets/d/1LnTHOuw5FROyZ8tNo1Zl270RhTDX1gfB2m7jtEU9F_k/edit?usp=sharing
on your sheet you will find a new tab called MK.Help.
This is how you find XIRR for an investment like what you have:
=XIRR({FILTER(D:D*E:E,A:A=H5);-I5},{FILTER(B:B,A:A=H5);TODAY()})
The key is that you need to add the CURRENT HOLDING and todays date at the end of the arrays of cashflows. The idea is to imagine that you liquidated the position right NOW.

Match Rows By ID and return a value from the row with the closest date before a specified date

I'm using Google Sheets and have dataset 1 pictured below, which includes ID, Date, Value. This dataset has a number of rows with the some duplicate ID's but different dates against them.
Dataset 1
I then have dataset 2 with ID, Date, Empty Column. I want to be able to populate the empty column with the value from dataset 1 that matches the row ID, however is pulled from the row with the closest date before the date specific in dataset 2. (Hope I've explained that well enough). Attached a couple of images for references. Any help would be really appreciated on this one!
Dataset 2
For clarity and maintenance, I am doing this in 2 steps. In theory it should be doable in one as described at sql with dates. I have also referred to dates with qoogle query, and looking there one may find simplifications. On the Dataset2 sheet, I added a column D, which may be hidden later if you like, and I named the first sheet Dataset1. in D2, I placed the following formula, which I then dragged down.
=iferror(index(query(Dataset1!$A$2:$C$11,"select MAX(B) where A='"&A2&"' AND B<Date'"&TEXT(DATEVALUE(C2),"yyyy-mm-dd")&"'"),2),"")
The iferror guards against the case where nothing is found, as is the case for ID 2 in your example. index 2, simply picks out the query result as opposed to the header "Max." When you get inside the query you can see it looking at your original data, and finding the largest date where the id's match and the Dataset1 date is less than that in Dataset2 for this line.
Now once you have the date you need (I am assuming there is just one entry corresponding to that date, otherwise you need to handle that), you can query again in B2 (and drag that down as well) with
=iferror(query(Dataset1!$A$2:$C$11,"select C where A='"&A2&"' AND B=Date'"&TEXT(DATEVALUE(D2),"yyyy-mm-dd")&"'"))
Again the iferror is for the same reason (to avoid a bad date format message for the empty one), and now we pick out the value for the item matching the ID and the date we calculated.
That is what your goal was.

How to get last value of column in multiple sheets and add them together

I'm currently trying to get the last value of Column "D" in several sheets, then add all the values together, then calculate a percentage based on a value from a main sheet cell.
I can get =VALUE(D:D) to work and =VALUE(Animations!D15), but not a combination of both which is what I need (since the size of the column will continue to grow).
It would be best if it was the last numerical value in column D, and not account for blank spaces or strings.
Thanks!
To find the last populated number in a column use Index with an approximate Match to 1E+99.
=index(sheet2!d:d, match(1e99, sheet2!d:d))
The above retrieves the last number in column D on Sheet2.
Google sheets will not process an array of worksheet names through INDIRECT like Excel will but a 'helper' column will take care of that. If you want to hard-code a series of worksheet names into a sum of index/match formulas, then Indirect isn't even necessary.
In the accompanying linked worksheet, I've used this method to retrieve the last number from columns with numbers, text and errors. I've thrown in the 'last number' cell address as well.
Linked spreadsheet

Google Sheets Formula for Pulling Specific Values in Two Ways

I'm trying to do a couple of different things with a spreadsheet in Google and running into some problems with the formulas I am using. I'm hoping someone might be able to direct me to a better solution or be able to correct the current issue I'm having.
First off all, here is a view of the data on Sheet 1 that I am pulling from:
Example Spreadsheet
The first task I'm trying to accomplish is to create a sheet that lists all of these shift days with the date in one column and the subject ("P: Ben" or S: Nicole") in another column. This sheet would be used to import the data via a CSV into our calendar system each month. I tried doing an Index-Match where it used the date to pull the associated values however I found that I had to keep adjusting the formula offsets in order to capture new information. It doesn't seem like Index-Match works when multiple rows/columns are involved. Is there a better way to pull this information?
The second task I am trying to accomplish is to create a new tab which lists all the dates a specific person is assigned too (that way this tab will update in real time and everyone can just look at their own sheet to see what days they are on-call). However, I run into the same problem here because for each new row I have to change the formula to reflect the correct information otherwise it doesn't pull the correct cell when it finds a match.
I would appreciate any and all information/advice on how to accomplish these tasks with the formula combination I mentioned or suggestions on other formulas to use that I have not been able to find.
Thanks in advance!
Brandon. There are a few ways to attack your tasks, but looking at the structure of your data, I would use curly brackets {} to create arrays. Here is an excerpt of how Google explains arrays in Sheets:
You can also create your own arrays in a formula in your spreadsheet
by using brackets { }. The brackets allow you to group together
values, while you use the following punctuation to determine which
order the values are displayed in:
Commas: Separate columns to help you write a row of data in an array.
For example, ={1, 2} would place the number 1 in the first cell and
the number 2 in the cell to the right in a new column.
Semicolons: Separate rows to help you write a column of data in an array. For
example, ={1; 2} would place the number 1 in the first cell and the
number 2 in the cell below in a new row.
Note: For countries that use
commas as decimal separators (for example €1,00), commas would be
replaced by backslashes () when creating arrays.
You can join multiple ranges into one continuous range using this same
punctuation. For example, to combine values from A1-A10 with the
values from D1-D10, you can use the following formula to create a
range in a continuous column: ={A1:A10; D1:D10}
Knowing that, here's a sample sheet of your data.
First Task:
create a sheet that lists all of these shift days with the date in one
column and the subject ("P: Ben" or S: Nicole") in another column.
To organize dates and subjects into discrete arrays, we'll collect them using curly brackets...
Dates: {A3:G3,A7:G7,A11:G11,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
This actually produces two rows rather than columns, but we'll deal with that in a minute. You'll note that, because there are two subjects per every one date, we need to effectively double each date captured.
Dates: {A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
Still with me? If so, all that's left is to (a) turn these two rows into two columns using the TRANSPOSE function, (b) combine our two columns using another pair of curly brackets and a semicolon and (c) add a SORT function to list the dates in chronological order...
=SORT(TRANSPOSE({{A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15};{A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}}),1,TRUE)
Second Task:
create a new tab which lists all the dates a specific person is
assigned too (that way this tab will update in real time and everyone
can just look at their own sheet to see what days they are on-call).
Assuming the two-column array we just created lives in A2:B53 on a new sheet called "Shifts," then we can use the FILTER function and SEARCH based on each name. The formula at the top of Ben's sheet would look like this:
=FILTER(Shifts!A2:B53,SEARCH("Ben",Shifts!B2:B53))
Hopefully this helps, but please let me know if I've misinterpreted anything. Cheers.

Resources