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

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.

Related

Trying to make comparison between different sheets of data in Google sheets using column pair values

I am trying to get to the point where my Google sheet is going to show up like the picture below.
Basically I am trying to find the common column in different table (sheet) and also make sure the type of the columns matches too. The columns are unsorted and won't be of equal length.
But I am unable to do so using vlookup or query which is becoming to complicated. I am attaching the link for the Google sheet.
https://docs.google.com/spreadsheets/d/1yk5J_R74yvYTOmOr5LHgMuLD--xT68pOaps8XvhOgy8/edit#gid=0
Try below formula-
=IFERROR(MAP(C7:C13,D7:D13, LAMBDA(x,y,IF(XLOOKUP(x,A7:A10,B7:B10)=y,"Match","Mismatch in Type"))),"No Match")
This should also work.
=INDEX(IFNA(XLOOKUP(--(VLOOKUP(C7:C13,A7:B10,2,0)=D7:D13),{0,1},{"Type Mismatch","Match"}),"No Match"))
This will spill results automatically. No need drag down.
Update: Use below formula as dynamic input range from source and target sheet without helper QUERY function.
=MAP(Target!A2:INDEX(Target!A2:A,COUNTA(Target!A2:A)),
LAMBDA(x,IFNA(XLOOKUP(XLOOKUP(x,Source!A2:A,Source!B2:B)=XLOOKUP(x,Target!A2:A,Target!B2:B),
{TRUE,FALSE},{"Match","Type Mismatch"}),"No MAtch")))
I think you have a typo in your Source table (you have 'emd_id' where you meant 'emp_id'). If you correct that, you can delete everything in F7 downwards and try the following in F7:
=arrayformula(ifna(if(sign(match(C7:C13,A7:A10,0))=ifna(sign(match(C7:C13&D7:D13,A7:A10&B7:B10,0))),"Match","Mismatch in type"),"No match"))
We are creating two arrays corresponding to whether the 'column' or 'column' AND 'type' entries match in both Source and Target, then using IF/IFNA to assign the required results based on whether the overall result was TRUE/FALSE/#N/A.
EDIT: To make the formula dynamic (as per the comment):
=arrayformula(lambda(source,target,
ifna(if(sign(match(index(target,,1),index(source,,1),0))=ifna(sign(match(index(Target,,1)&index(Target,,2),index(source,,1)&index(source,,2),0))),"Match","Mismatch in type"),"No match"))(
Source!A2:index(Source!B2:B,counta(Source!B2:B)),
Target!A2:index(Target!B2:B,counta(Target!B2:B))))

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

Query Importrange in Google Sheets Not Importing Correctly

We are using Google Forms to collect data on our students. They use the same Google Form for all students, but as part of the form, they are asked the students name.
The data that ends up being collected you can see on the tab Form Responses 1 on the Google Sheet linked here.
I am attempting to use ImportRange to create a tab for each of the students. The formula that I am using for just one of the students is...
=QUERY(IMPORTRANGE("1nJANDP1fiQunxfxEf-EjwJrnIRICv6kLhYYY9XBXtD4", "Form Responses 1!A:I"),"SELECT * WHERE Col3 = 'Adam N.'")
You can take a look at the tab called Adam N. and you'll see it is kind of working.
One thing that doesn't seem to be working is when there is a text value in columns E-I, that text value doesn't end up showing on the Adam N. tab. Any ideas how I can get both the numbers and the text values to show up?
The other thing that seems to be a problem is the fact that on the Adam N. tab, the very first row has the same headers as the Form Responses 1 tab, but it also has the very first line of data. Any way to remove that?
Importrange is not needed since you are 'importing' from within the same spreadsheet. Also, I'd recommend using the (optional) header argument in query().
It is often noted that users are tempted to mix data types within a column. The query() function will give undesirable output. If a column is intended for numeric values then only numerical values must reside in that column. Date columns must only contain dates and text columns only contain text values.
This does not mean that numbers cannot appear in a text column as long as they are in a text format. So it is important to plan the columns in a table to make sure this rule is maintained regardless if the data table is created manually or via submissions from a Google Form.
Generally, the query() function will assume the greater number of cell types in a column to be that data type. For example, if there are 100 numbers and 20 text values in the same column then a numeric value will be assumed for that column. There is a good chance the text values will just be ignored. One way to avoid this, would be to convert everything to text.
See if this works
=ArrayFormula(QUERY(to_text('Form Responses 1'!A:I),"WHERE Col3 = 'Adam N.'", 1))

Importrange but only include certain values

I would like to create a new sheet from Google Form data which only imports cell data that matches specific criteria. Respondents have five response options for a number of questions (all questions have the same five options). I want the new sheet to only show the data in the cells that fit my criteria and the cells that don't, should be blank. I would like all rows and column formatting to remain the same.
I've got the import range part down, but I don't know should I use query, filter, if, or some other function?
Within the same spreadsheet, QUERY works well. You could also use QUERY(IMPORTRANGE( or just IMPORTRANGE if you want it to go to a different spreadsheet.
As Rubén said, if you want to maintain all the formatting, without manually doing it yourself on the destination sheet, you'll need to use script.
Query Reference
EDIT
See Sheet3 HERE. Make a copy to edit.
Any cell with a blue background has a formula. The main one is below.
=ARRAYFORMULA(IF('Form Responses 1'!D3:DD="","",SWITCH('Form Responses 1'!D3:DD,$D$1,"",$E$1,"",'Form Responses 1'!D3:DD)))
You will not be able to edit those columns. If you need to edit (like the "Comments/Adaptations" columns, you could modify the formula above and apply it column by column.
If that works, please click the green check mark to accept the answer!
Beside the number format, any formula keeps the format of the source range, so if your the format includes fonts styles, bold, italics, colors, etc., instead of a formula you should use a script.

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

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.

Resources