referencing a grouped date column using GETPIVOTDATA in Google Sheets - google-sheets

I'm doing an analysis of sales data in Google Sheets and I'm building a dashboard with information about different sales reps. I'm trying to use the GETPIVOTDATA function to reference a year-quarter group in my pivot table, but I can't get the function to return the correct value.
In the pivot table, I have specific timestamps grouped by year-quarter and organised as columns. I have the individual sales reps and their teams organised as rows:
[Google Sheets pivot table]. I want to use GETPIVOTDATA to get the number of SQLs for a specific sales rep in a specific quarter.
The function will only return the Grand Total for the sales rep (column F in the picture), or if the Grand Total is disabled in the pivot table, it returns a #REF! error.
I tried many iterations of the GETPIVOTDATA function. I also tried making a helper column in the original data that lists the specific year and quarter instead of the timestamp. Neither of these worked.
I realise that I can use an INDEX MATCH or VLOOKUP instead, but I want to be able to change the pivot table later without having to change the formula.
If anyone knows what I'm doing wrong (or if what I'm trying to do is even possible with a GETPIVOTDATA function) I'd really appreciate advice! I can't seem to figure it out.

Related

How to create a Google Sheet table of ranked person by date and rank from a list

I have a Google Sheet with daily ranked items expanding with new data everyday in the Raw Data Table A2:C.
I would like to generate a report matrix similar to table in E2:J using one formula so that we don't need to manually copy formulas in each cells in the report table from time to time.
It would be ideal to have one formula at cell E2 (or E3, F1, F2) only that will automatically generate as many rows and columns in the report table based on the data in Raw Data Table. This way, the report table will not needed to be maintained on a daily basis (like copying formula everyday as data expanded).
There are less elegant ways to do it like pre-copy formula into a large number of cells or using Google App Script to generate the table. However, I believe an advance query() or a complex formula mixing query(), filters() and/or arrayformula() can do the job! Just wonder if anyone of the Google Sheets query() expert can help!
try:
=QUERY(A2:C; "select A,max(C) where A is not null group by A pivot B"; 1)
Here's a possible solution:
=ArrayFormula(LAMBDA(dates,ranks,{A2,ranks;dates,IFNA(VLOOKUP(dates&ranks,{A3:A&B3:B,C3:C},2,0))})
(UNIQUE(A3:A),TRANSPOSE(UNIQUE(SORT(B3:B)))))

Google Sheets Count Unique Dates based upon a criteria in different columns

I am trying to find a formula that will give me the count of unique dates a persons' name appears in one of two different columns and/or both columns.
I have a set of data where a person's name may show up in a "driver" column or a "helper" column, multiple times over the course of one day. Throughout the day some drivers might also be helpers and some days a driver may come in for duty but only as a helper. Basically all drivers can be helpers, but not all helpers can be drivers.
I've attached a link to a sample sheet for more clarity.
https://docs.google.com/spreadsheets/d/1GqNa1hrViX4B6mkL3wWcqEsy87gmdw77DhkhIaswLyI/edit?usp=sharing
I've created a REPORTS tab with a SORT(UNIQUE(FLATTEN)) Formula to give me a list of the names that appear in the DATA Tab.
I'm looking for a way to count the unique dates a name from the name (Column A of the REPORTS Tab) appears in either of the two columns (Column B and/or C of the DATA Tab) to determine the total number of days worked so I can calculate the total number of days off over the range queried.
I've tried several iterations of countif, countunique, and countuniqueifs but cannot seem to find a way to return the correct values.
Any advice on how to make this work would be appreciated.
I think if you put this formula in cell b7 you'll be set. You can drag it down.
=Counta(Unique(filter(DATA!A:A,(DATA!C:C=A7)+(DATA!B:B=A7))))
Here's a working version of your file.
For anyone interested, Google Sheets' Filter function differs slightly from Excel's Filter function because Sheets attempts to make it easier for users to apply multiple conditions by simply separating each parameter with a comma. Example: =filter(A:A,A:A<>"",B:B<>"bad result") will provide different results between the Sheets and Excel.
Excel Filter requires users to specify multiple conditions within parenthesis and denote each criterion be flagged with an OR condition with a + else an AND condition with a multiplication sign *. While this can appear daunting and bizarre to multiply arrays that have text in it, it allows for more flexibility.
To Google's credit, if one follows the required Excel Syntax (as I did in this answer) then the functions will behave the same.
delete what you got and use:
=QUERY(QUERY(UNIQUE({DATA!A:B; DATA!A:A, DATA!C:C}),
"select Col2,count(Col1),"&D2&"-count(Col2)
where Col2 is not null
group by Col2"),
"offset 1", 0)

Formula for looking up and filtering data from a sheet

I want to do a complex formula using google sheets:
I have a list of place that will be visited by different people.
Some places are not to be visited, marked with /
Some places need to be assigned, marked with ?
Wanted outcome:
A list of cells that changes every day automatic.
An overview of who is going where that day and what needs to be assigned.
So I need a formula that can select a row based on today() and then filter out Persons in that row. Then for each person, another formula that looks up the first row in the table and puts duplicates together.
Example:
Wanted outcome:
Link to excel file, but it needs to work in google sheets too: xlsx
My solution is not the most elegant but it does the job.
First I build a column with date and unique persons or ? in this column:
=unique(sort(transpose(index(A1:H10,match(today(),A1:A10,0)))))
Then I find Places corresponding to these persons (I use filter function for it and then I use textjoin to keep them in single cell).
The formula is copied down as filter function does not accept a range and arrayformula as a filtering criterium.
My solution is available here:
https://docs.google.com/spreadsheets/d/1GTy_UaFP8LbA8OLnEhT_R_twpDCIWCuvQfBAigqtbR0/copy

How to apply arrayformula to a series of columns

I'm trying to make a spreadsheet to track membership for an organization.
Basically my design is an input sheet with columns of names associated with expiration dates, then another sheet that collects all the unique names and all of their associated expiration dates, and then one last sheet that filters the names into only those with expiration dates in the future.
I am able to collect all the unique names into one column using an arrayformula, but I am stuck trying to do a lookup operation of some kind that, for each name, will look for the name in each column and if it appears then it will add the associated expiration date to it's list (and otherwise add a blank cell, and then I can filter out the blank cells).
Is there a way to use vlookup or anything else in an arrayformula to do a series of operations for all columns in a range? Also, I want to use arrayformula because I want the formula to be infinite so the spreadsheet can keep growing. I've tried using
=ARRAYFORMULA(IF(ISERROR(VLOOKUP(A1:A,Sheet1!A2:200,1,FALSE)),,Sheet1!A1:1))
But vlookup, and anything else I tried like match, interprets Sheet1!A2:200 as a single range and performs a lookup only in the first column and does not do a separate lookup in each column.
For example, I might have this input on Sheet1
And want this result on another sheet
I suspect the combination of what you would really like and what is reasonably practical is a script but the following is an array formula, though would be cumbersome to extend and does require copying down (from B1):
=split(if(ISERROR(match(A1,Sheet1!A:A,0)),"",Sheet1!A$1)&"|"&if(ISERROR(match(A1,Sheet1!B:B,0)),"",Sheet1!B$1)&"|"&if(ISERROR(match(A1,Sheet1!C:C,0)),"",Sheet1!C$1),"|")
Assumes a unique list of names in ColumnA, such as created by:
=unique(QUERY({Sheet1!A2:A6;Sheet1!B2:B6;Sheet1!C2:C6},"where Col1 is not NULL"))
in A1.

Setting formula range from first to last populated cell in a column?

For a league I run we keep track of games played and w/l/t and calculate that into a ranking score. The player name is listed in column U and the ranking score in column AD of a fixed table. I then use an array formula to list the players in ranking order in column E (then vlookup to pull in other stats based on the value in E for that row). Specifically I use this formula in column E:
=ARRAY_CONSTRAIN(ARRAYFORMULA(INDEX($U$4:$U$153,MATCH(LARGE($AD$4:$AD$153-ROW($AD$4:$AD$153)/COUNT($AD$4:$AD$153),ROW(E72)-ROW(E$4)+1),$AD$4:$AD$153-ROW($AD$4:$AD$153)/COUNT($AD$4:$AD$153),0))), 1, 1)
I need to be able to add players to the table in U:AD without having to edit the formula every time, i.e. from $U4:$U153 and $AD$4:$AD$153 to $U4:$U154 and $AD$4:$AD$154 in all the various places in the formula then copy the new formula all the way down.
Is there a way that I could define the range as $U$4:$U(last populated row) and the same for column AD in the above formula?
I eventually be using this in both Excel and Google Sheets so I would really like to avoid scripting. First I'm looking to solve this for Google Sheets.
Here is a copy of the sheet I am working on.
You could use INDEX and COUNTA
Instead of $U4$U153,
$U4:INDEX(U4:U,COUNTA(A4:A))
The COUNTA portion will give the number of populated rows and feed it into INDEX to give $U4:$U153
The answer for the Google sheet that you shared.
skip to the end for the simple solution
I used the indirect method by entering a formula in E1 that counts the AD column for player stats and adds 3 to get the last row. (I was going create the full range AD4:AD?? but you also have U4:U73 in the formula)
=counta(AD4:AD)+3
I then changed your formula use indirect, indirect("$AD$4:AD"&E$1), to reference the last row number in cell E1 to create the required range.
=iferror(ARRAY_CONSTRAIN(ARRAYFORMULA(INDEX(indirect("$U$4:U"&E$1),MATCH(LARGE(indirect("$AD$4:AD"&E$1)-ROW(indirect("$AD$4:AD"&E$1))/COUNT(indirect("$AD$4:$AD"&E$1)),ROW(E4)-ROW(E$4)+1),indirect("$AD$4:$AD"&E$1)-ROW(indirect("$AD$4:$AD"&E$1))/COUNT(indirect("$AD$4:AD"&E$1)),0))), 1, 1),"")
I discovered by accident that if you remove the ARRAY_CONSTRAIN from your formula and change U4:U73 to U4:AC73 then the formula will populate the scores to the right of your formula where you currently have vlookups. I put an example of this in E4 but note that you will have to delete the vlookup formulas if you want to fill the formula down otherwise it will show REF
I also added iferror so that the formula can be copied to the same row as the end of the "open slots" in column A without showing errors.
Also, I got to this point and was thinking that since you're using Google Sheets, a better way to do this could be to use the QUERY function to pull the data and also sort it using ORDER BY with a single formula in cell E4.
I've not really used the QUERY function but maybe it's time to learn.
EDIT
Turns out it doesn't take much learning
=QUERY(U4:AD,"SELECT U,V,W,X,Y,Z,AA,AB,AC ORDER BY AD DESC")
Put the formula above in cell E4 and delete everything beneath and scores to the right and you're done. you'll notice that there is no indirect because Google understands that you don't want the blank rows.
https://docs.google.com/spreadsheets/d/16IclEmKwDFdInIAZhH2vt-tLJ5pbwX06jv9xrUXwhnY/edit?usp=sharing
Why are you using $ signs around U4:U153,remove $ signs for rows that will give you flexibility while keeping columns fixed.As your drag the formula,the data array will append the newly filled cells or you can create table using Ctrl+T that will automatically expand as you keeping adding data.

Resources