Excel Pivot count occurances under condition - excel

In excel, and preferably using pivot tables, I want to count the number of occurrences that have a specific value for different line items.
Tom | yes
Tom | no
Max | n/r
Max | yes
Max | yes
Max | no
The pivot table should have two line items (Max/Tom), one column that counts the sum of occurrences of "yes" and "no" and one column that counts only "yes". The result would be that I can say "Max has won 2 out of 3 relevant cases; Tom has won 1 out of 2 relevant cases"
I know how to do it with formulas, but was wondering if using pivot-tables is also a possibility.

If you can add helper columns I would add two, one for yes and one for no. In the yes column (assuming your data starts in cell A1), in C2 type =--(B2="yes") then in D2 type =--(B2="no")
This will return a 1 if the cell is yes or no like follows:
Name Data Yes No
Tom yes 1 0
Tom no 0 1
Max n/r 0 0
Max yes 1 0
Max yes 1 0
Max no 0 1
Then create a pivot table, put Name as Row Labels, then in Values have Sum of Yes and Sum of No
http://oi63.tinypic.com/10z5j55.jpg

Additional fields are not necessary. When creating the pivot table, set Name equal to your Row value and Data for your Columns value. Then, drag the Name field into the Values area and voila! Screenshot attached.

Related

How can I assign a value to a cell by referencing a seperate table in Excel/Mac Numbers?

Table 2
Pts
# of tix sold
0
100
1
200
2
300
3
400
4
500
5
600
Example: In Table 1 Tim sold 198 tickets. He didn't make it to 200 tickets sold, so he gets 0 pts. Bill sold 220, so he gets 1 pt. The points show in the cell next to the name on Table 1, but references table 2.
I tried using xlookup and index, but I don't really know what I'm doing.
XLOOKUP provides several matching modes, and one is "exact match or next smallest" which is what you want. If the lookup value is 225, I want it to start down the list, and if it finds 225, it selects that row; if it encounters any number > 225 then it knows it's gone too far and selects the previous number. This sounds like the logic you want.
Assume:
Tim's ticket count is in B2, and you want his points in C2;
The lookup table is on a second worksheet, titled "Table2";
The lookup table headers are A1:B1, and the data is the 6 rows below that;
The lookup table should be in ascending ticket count order.
Then, in table1 cell C2 place this:
=XLOOKUP(A2, table2!$B$2:$B$7, table2!$A$2:$A$7, "", -1)
And copy it down the rows of column C.
The -1 argument tells lookup "exact match or next smallest".

compare 2 excel columns with data in adjacent columns

I have seen a few answers which were close to what I am looking for, but can't quite figure it out. I apologize as I am not a programmer, but am tasked with these types of things periodically.
I have a spreadsheet with data in multiple rows. I would like to compare column A with C and have them align, and then the data in B move with column A. (I can rearrange the columns if need be to make this work.
I have this:
Inventory ID# count Original ID# vendor item number
1234 2 1000 vendor 1 1234566
1456 1 1234 vendor 2 546564
7000 3 1456 vendor 3 af4566
2003 vendor 4 56778
7000 vendor 1 788asd
What I want it to look like is after:
Inventory ID# count Original ID# vendor item number
1000 vendor 1 1234566
1234 2 1234 vendor 2 546564
1456 1 1456 vendor 3 af4566
2003 vendor 4 56778
7000 3 7000 vendor 1 788asd
I have tried macros, and VLOOKUP, but can't figure out how to have the count move with the inventory ID # Thank you for your help.
I'll assume your data starts in Sheet1!A1
Move the Invenotry ID# and count columns to a different sheet (say, Sheet2). Then replace the value in cells A2 with the following:
=IFERROR(VLOOKUP($C2,Sheet2!$A:$B,1,FALSE),"")
and similar for cell B2:
=IFERROR(VLOOKUP($C2,Sheet2!$A:$B,2,FALSE),"")
Fill it down. The VLOOKUP will place your id's and counts in the right rows, and the IFERROR( ... ,"") part will put a blank string where there is no match, so it will look like you desired table
If your data starts from cell A1, insert 2 columns C and D like below,
Enter the below formula in cell C2 and drag it right to column D and then down throughout the range,
=IFERROR(INDEX($A:A,MATCH($E2,$A:$A,0),COLUMN(A1)),"")
You can then copy-pastespecial Column C and D to A and B and delete C and D.

excel pivot table - count appearance of certan value in column

let's say i have folowing data for my excel pivot table:
country_id user_id answer
---------- ------- ------
1 1 Y
1 2 Y
2 3 N
2 4 Y
3 5 N
i would like to count how many "Y" i have per country.
If i put "answer" in Values as "Count of answer" i get 1 for each row. How can i count only "Y" answers?
so the result will be:
country_id answerY
----------- -------
1 2
2 1
3 0
br
Y
I have a solution similar to #pkg. Add one more column in your data and call it "answerY" with the formula:
=IF(C4="Y",1,0)
or, if your data is in a table:
=IF([#answer]="Y",1,0)
Now, set up your pivot table as follows:
Row lables: country
Values: answerY (sum)
Ordinarily I'd say to add a calculated field in a pivot table, but calculated fields work off of the aggregate values, and I can't think of a way to do this with a straight pivot table.
If you have the ability to use PowerPivot, you could create a custom column or a Dax expression that would handle this.
I'm not sure you can do that in a pivot table, but if you would like to do it outside of a pivot table you could make a couple of columns with these formulas:
Column D:
=IF(C2="Y",1,0)*A2
Column E:
=COUNTIF(D$2:D$6,B2)
This assumes that all user IDs are unique and sequential, and D$6 needs to be replaced with whatever is the last value in the column. Column E will have the values you described as answerY.

Count specific number of duplicates in excel

I am working in Microsoft Excel 2013 (Windows OS).
I have a column of data as below:
Data
A
B
A
C
B
A
A
B
D
As we can see, only A appears 4 times, only B appears 3 times whilst C and D appear 1 time each.
I need a formula/method to count how many times a number of number of duplicates appears and display it in a table like below:
Duplicates | Number of values duplicated this many times
4 | 1
3 | 1
2 | 0
1 | 2
Does anyone have a way of doing this?
This might work without VBA. Assuming Data is in A1, enter Count in B1 and in B2:
=IF(COUNTIF(A$1:A2,A2)=1,COUNTIF(A:A,A2),"null")
copied down to suit. Then insert a PivotTable with Count for ROWS and Count of Count for VALUES.
Result should look so:
The nulls should be ignored and a zero count for 2 duplicates has to be inferred. The order can be adjusted to suit.

Excel vlookup expansion

I currently have an excel worksheet with three columns
id annotation person_id
1 yes 1
1 no 2
1 yes 3
I'm trying to reformat this on another worksheet into a table that looks like:
id 1 2 3
1 yes no yes
I'm using this
vlookup: =VLOOKUP(A2,sheet2!$F$1:$G$10,2,FALSE)
where a2 is the id and f$1:g$10 is the range of data for that particular person.
At the moment I'm doing this per person and its tedious - there's thousands of people. I need a way to incorporate the person_id into my vlookup so that, if the person_id in the column header matches the person_id in sheet 2 and both ids match, then insert the annotation.
This appears to be a good candidate for an INDEX-MATCH formula, with a multi-condition MATCH() formula to account for both ID criteria. The formula below places the raw data are in A1:C4 and the reformatted data in E1:H2, so you will need to change the references:
In cell F2, I've entered {=INDEX($A$1:$C$4, MATCH(1, ($A$1:$A$4=$E2)*($C$1:$C$4=F$1), 0), 2)}, which yields
[A] [B] [C] [D] [E] [F] [G] [H]
[1] id annotation person_id ID 1 2 3
[2] 1 yes 1 1 yes no yes
[3] 1 no 2
[4] 1 yes 3
The relative references on $E2 and F$1 allow the filling of the formula across rows and columns.
To explain the formula a bit:
In the INDEX() formula, the first argument $A$1:$C$4 is the raw data "table" (array).
The second argument searches for the row where the value ($A$1:$A$4=$E2)*($C$1:$C$4=F$1) is exactly (given by the third argument, 0) equal to 1.
($A$1:$A$4=$E2)*($C$1:$C$4=F$1) is the multiplication of two TRUE/FALSE statements, which is equal to 1 when the main ID in col A is equal to the ID value in E2, and the person ID in col C is equal to the column header in F1.
The final argument, 2, is the column in the data table from which to look up the result.
You may want to consider using another MATCH() formula to dynamically identify the look-up column based on the column header; e.g., instead of 2, use MATCH("annotation", $A$1:$C$1, 0).
Important notes:
The formula needs to be entered as an array formula using Ctrl+Shift+Enter.
This method assumes the combinations of id & person_id are unique.
Also, note that this formula is clearer with named ranges: e.g. (using the suggested second MATCH() function instead of 2), {=INDEX(RawData, MATCH(1, (ID=$E2)*(PersonID=F$1), 0), MATCH("annotation", Headers, 0)}.
You could do like this
First create a new column on the first table =B2&D2
A B C D
1| id annotation person_id
2| 11 1 yes 1
3| 12 1 no 2
4| 13 1 yes 3
And then on the second table use a formula like this
=VLOOKUP(B16&C15;A2:C4;3;FALSE)
B C D F
14 1 2 3
15 1 yes no yes
16 2

Resources