Cannot find how to reference total of group in Google pivot table - google-sheets

Cannot find how to reference total of group in Google pivot table.
I am trying to get % of groups total (134.88/138.32)*100 = 97%, i.e.:
In Excel there is built in function:
In Google Sheets there's only built in function for whole column or whole row. And documentation does not give much help.

The documentation is poor but In Gsheets theres only built in function for whole column or whole row is incorrect. Assuming your pivot table starts in A1 something like:
=GETPIVOTDATA("D",A1,"B","01 Project task - translation","C",C2,"A",1)/GETPIVOTDATA("D",A1,"C",C2,"A",1)
formatted as Percent will return the percentage you require, provided you apply the correct column labels in place of the substitutes used above (since you neglected to provide any source data) and you substitute the final 1 with whatever is in the cell to the left you have failed to show all of (assuming the pivot table has only a single column to the left).
The catch is that the dates in the source sheet must be Text format.

Related

How do add a Percentage column to this Google Sheet pivot table

I have a pivot table, in Google Sheets, and want to add a percentage column.
EDIT: here is a link to a sample spreadsheet: https://docs.google.com/spreadsheets/d/12qyhOtKphW1iBWAOtfDHU1RdZRZ_Nq91eQtdghZzIyc/edit?usp=sharing
Below you can see the pivot table with the column (E) that I've manually added next to it, showing what I want to achieve, but as part of the pivot table, which is a simple:
E4=D4/C4
However, I have tried adding a Calculated Field under Values but can't work out the right formula; this didn't work:
='Checked In'/'Events'
nor did:
=D4/C4
I'm sure it's something simple, but I can't for the life of me work it out. Can anyone shine a light on what I'm doing wrong please?
Short Answer: Only use the column headers of the raw data and not the column headers of the other existing calculated fields.
Note: Since you have not shared a sample spreadsheet, I have made a sample data just to show the process.
Sample Raw Data
Creating a Pivot Table
Select the desired data to be added to the table which only includes the useful column headers (like the one selected in the sample raw data image).
Add a Calculated Field
To add a calculated field, look for the Values section in the Pivot table editor and click add (as shown above). To enter a formula, the pivot table editor requires you to use the column headers instead of the cell range (A1 notation). The formula you provided works just fine. In this case, I used ='Checked in'/Events to check if column headers with one word do not necessarily need single quotation marks (which will result in the following):
Note: Always use 'string' (single quotation mark) format in using column headers especially when the column headers contain spaces (like Checked in in the example).
Note: You may change the Column Header Output just by selecting the cell and renaming it.
Sample Modifications
You may also use other Google Sheets functions in the formula just like:
Which results to:
Reference
Create & Use Pivot Tables
Additional Info
When trying to add additional calculated fields using data based from other calculated fields, always use the original column headers of the raw data and not the column headers of the calculated fields as it returns an error just like the one below:
In your case, I modified your formula to
=COUNTA('Venue Name')/COUNTUNIQUE('Event Date')
Since both Venue Name and Event Date are the column headers of your raw data and not Checked in and Events. The current output of the corrected formula should look like this:
To address the decimals in the output values, you may refer to the Sample Modifications section of this answer.

How to use AVERAGEIF in Google Sheets, only addressing columns with a specific text

In Google Sheets, I'm trying to use AVERAGEIF to calculate an average of only some of the columns in another table.
The columns to be included in the average are marked by some text in a specific cell (e.g. the first or last row of that column).
Some columns are to be included in several averages, so the text in the top\bottom row would include several words (effectively meaning I'll need some sort of substring check such as FIND).
I've tried using AVERAGEIF() in conjuction with FIND() but couldn't get this to work.
Any ideas?
Here is an example of how the data sheet looks like, and how I would expect it to work
You can use following formula:
=ARRAYFORMULA(AVERAGE(IF(ISNUMBER(SEARCH(D2,A2:A9)),B2:B9,"")))
Edit:
For table mentioned in comment you must change ranges:
=ARRAYFORMULA(AVERAGE(IF(ISNUMBER(SEARCH(E2,$A$1:$C$1)),$A$2:$C$4,"")))
You can use a query
=AVERAGE(QUERY(TRANSPOSE($A$1:$D),"where Col1 contains '"&D1&"'"))
Functions used:
AVERAGE
QUERY
TRANSPOSE

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.

reference cell via two partial matches on another cell

I need to match two conditions on the cell Name and add the price information into cell price if both condition match. In other words, if Name contains both conditions, get the price. I tried different approaches using QUERY, SEARCH; FIND; VLOOKUP but I got stuck somewhere in the middle. Here's the example sheet (Google Spreadsheet solution preferred over Excel):
https://docs.google.com/spreadsheets/d/1zwG3_5Ctg_IZ1kI04Uee-qIvMrNQ4GmEwySmYcMKLfA/edit?usp=sharing
Maybe important: Both, the Name values as well as the whole reference table get pulled from other files dynamically. So I don't know anything concerning order or length of these columns in advance, not even if there are matches at all.
In addition to previous answer AND given the current set of data (in a Google spreadsheet), in B2 try:
=ArrayFormula(iferror(vlookup(regexreplace(A2:A; "[^A-Z]"; ""); {E2:E&F2:F\G2:G}; 2; 0)))
and see if that works ?
Based on your spreadsheet table:
you can try the following formula:
this formula works in excel not in google spreadsheets
=IFNA(INDEX($G$2:$G$6;MATCH(1;COUNTIFS(A2;"*"&$E$2:$E$100&"*";A2;"*"&$F$2:$F$100&"*");0));"NOT FOUND")
this is an array formula, so press ctrl+shift+enter to calculate the formula.
i think it will do the job.
here is the example file to download

Is it possible to set a default value of zero when using COUNTA function in Google Sheets?

I'm using a pivot table in a Google Spreadsheet that counts the occurrences of different types of event-types on given dates. The events are listed on one sheet, with a column for "Date" and column for "Type." Based on this a Pivot Table is produced.
The trouble is that for dates when an event-type is non-existent, COUNTA returns empty. I'd rather it return 0.
The reason is for charting and statistical purposes when you create a chart from this data, it interpolates between values, ignoring empty cells. I'd prefer that it display zero on the chart on the days when these event types don't exist...
Is this possible?
UPD: sorry, I've misunderstood what you need.
What if, on another worksheet, you write the following?
=arrayformula(IF('PivotSheetName'!A1:Z100="";0;'PivotSheetName'!A1:Z100))
(This formula makes a copy of your Pivot table on the new worksheet,
replacing empty cells with 0; moreover, the control elements of the
pivot table are copied to the new worksheet as well)

Resources