Pivot table giving wrong count by 1 - excel

I have a pivot table with column A which gives me a count of "Y's" from another worksheet. It either has a Y in the cell or it is left blank. For some reason the count is off by 1. I have another column B that has the correct count of Y's which is 55 while this column shows 56, any thoughts?
Note: Both column A and B should have the same count of 55. When I check the worksheet manually, they both have 55 Y's

A good way to fix and/or eliminate this issue from happening in the first place (counting empty cells) is by right-clicking on the pivot table, click on "value field settings" and instead of clicking on "count" pick/click" count numbers". Then right-click on the pivot table and click refresh.
This ensures that the pivot table counts cells that actually have a number in them and not merely a value that we can't see.

I faced this similar issue (of 1 less count for one element) and had to do some random pivot table counts of general items. Found two things:
Affects the count of the first element of a list.
It is because the the pivot table takes the first element of the list as the heading.(you can see it shows it as count of whatever the first element is).
SOLUTION
Add some heading above first element in the list and include it in the selection for the pivot table. The count should be correct after doing this.
(This issue of 1 less count which is unnoticeable for lists that you are not double checking counts by other methods can cause devastating issues and losses for engineering, monetary calculations etc.)

Related

How do you count the occurrence of same data set in two columns-set in excel?

How can we count the occurrence of each set of data? For eg I want to check how many time the customer country in column A comes alongside country in column B ie (How many times Australia-Australia occurs in column A and column B?). The result for unique occurrences are place in right hand side of the sheet. I have found out unique occurrences of the sets and want to count how many times each occur.
You asked for a formula, but a pivot table can do the same thing faster; and without requiring you to create the table for unique countries (option found under insert, usually the first button in the ribbon):
This is how it looks like after pulling the fields in the right 'boxes', the 'Tabular' report layout is selected and the subtotals turned off.
You can make 'Australia' repeat itself too under report layout if so you wish.
Again, SUMPRODUCT is your friend:
=SUMPRODUCT(--(($A$2:$A$11&$B$2:$B$11)=(D2&E2)))
You can use COUNTIFS function as below.
=COUNTIFS(A:A,D2,B:B,E2)
Adjust the ranges to suit your data and copy down.

Restructuring data in excel

I am trying to condense data in a specific way. I want any occurrences of the number 1 in each column to show up as 1 (regardless of how many times it occurs) with the corresponding site, in the corresponding column. Some sites occur multiple times in the original data, and I want to make it so that only one of each unique site shows up in the resulting data table with a 1 for the corresponding column if there any 1's in the column from the original data.
I would think it would be a vlookup function, but I have tried many different things and I am really stuck on this.
Image of original data and what I am trying to do:
Thank you
This assumes that your data set only contains 1 or blank and this approach uses a Pivot Table with MAX function. Below are details in case anyone doesn't know Pivot Tables.
Select a cell in your data and insert Pivot Table. Note, I added a title for column A, as you need that in the Pivot Table.
Click in the created Pivot Table and the PivotTable Fields dialog should pop up. If not, right click in Pivot Table and select Show Field List.
Drag the Field names (Code, a, b,& c) down to the appropriate blocks below. (Values under Columns will be created for you.)
Click on the drop down arrow next to each field name and select Max. That will rename it to "Max of ...". If that bothers you, then you can type the name you want into the Custom Name field. Note, it will not let you type the same name as the field name, eg a, but it will work if you put a space in front of it.
Given that the Pivot Table would be a lot of work for a large number of columns, here is a formula based approach. Put this formula in cell G2, then drag it down and across to fill your new table.
Note, you will have to populate all codes that you have in column F. And if any new codes are added later you will have to keep this updated. One of the advantages of a Pivot Table is that it will do this for you.
I know that you won't be putting this in these cells, so adjust accordingly. In fact, I would recommend this be in another sheet.
=IF(COUNTIFS($A:$A,$F2,B:B,1)>0,1,0)
COUNTIFS($A:$A,$F2,B:B,1)
This will count each occurrence when the value in column A matches your code $F2 AND the value in column B equals 1.
If that count is >0, then you know that at least one match was found and the IF will return 1, otherwise 0.

Finding Duplicates across a thousand lists

I have over 1,100 lists that each contain no more than 30 items in them. I am trying to see if there are any items within the lists that appear in all lists. I was initially thinking that I would need to compare the list in column A to the list in column B, store the duplicates, then compare the duplicates to the list in Column C, store the new duplicates, compare the new duplicates to the list in Column D, and so on until all the lists have been covered.
My questions are:
1.) Is this the correct way to approach this?
2.) If so, is there a simple VBA code that could be used to do this?
Deduplicate each list using Data > Remove Duplicates
Collate all the lists into one long list
Create a pivot table with the column of items as the Row dimension
Use the same column as the Value displayed in the pivot table, and aggregate using Count.
Sort the pivot table in descending order of that count.
The count shows the number of lists in which each item appears. If any have a count of 1100 then they must occur in every list.
Here's my non VBA solution to this fun problem. The plan is to search each item in any one list and compare to all the other lists in the table.
Start off by inserting a new "A" column to the left of your table. Copy any list and paste to A35.
if your goal is only to find items occuring in all lists, choose the smallest list.
if you would like to analyse, choose the largest list or even multiple lists.
you could include all items by copy/paste TRANSPOSE the entire table to new sheet. then you have less than 30 colums. copy paste each into one column and delete duplicates of this list with data--> remove duplicates.
Now you need to create a formula in cell B35 that searches for the string in A35 in the range B1:B30. You drag the formula all the way right and down.
=COUNTIF(B$1:B$30,$A30)
The results will be the count of each item found in each list. In order to see if any item is in all lists, then all columns within the specific row should count at least 1 item. To the right of the results, see what the minimum value in the row is with:
=MIN(B35:API35)
(assuming your table ends in column API)
If any of your rows have a minimum of 1, then the item is included in all lists.
You could then also sum up the line to see which items occur the most and you could use the "max" instead of "min" to see if any list has duplicates.
Please try to use this
If it will not work I can help you with Macro VB code.
Logic will be as below:
1. Keep 1st column as base to check all the other column
2. Check each 30 cell of the 1st column in a loop with all the other column cell.
3. Stop the loop, if you don't the value in an entire column.

Count number of unique combinations of two columns

I have a spreadsheet of statistics from sports games over a season, for different leagues - each row holds a single event that happened in a game, such as a penalty. There are many rows of events for each individual game. One of the columns is the league, another is the home team and another is the away team. How can I count the total number of games in a given league? In other words, I would need to count the number of unique pairs of strings from Home and Away, where League = "Ligue 1".
EDIT
I have tried:
=SUMPRODUCT(1/(COUNTIFS(E2:E81078,"Ligue 1",F2:F81078,F2:F81078,G2:G81078,G2:G81078)))
which returns a DIV/0 error (it does work if I dont include the column E = "Ligue 1" criteria).
This is similar to your formula but deals with the division by zero
=SUM(IFERROR((1/COUNTIFS(E2:E81078,"Ligue 1",F2:F81078,F2:F81078,G2:G81078,G2:G81078)),0))
Enter it with Ctrl+Shift+Enter rather than just Enter. If done correctly you will see {} around the formula
Try not to use ranges that are bigger than your data because it will slow these kind of formulas down significantly
Update
This might also work if your data is ordered the way you show in your question. It counts the number of times the home team changes in Ligue 1 data :
=SUMPRODUCT((F3:F81079<>F2:F81078)*(E2:E81078="Ligue 1"))
Note that the ranges in column F are offset by one row
You can do this with a Pivot Table.
Add a "helper" column where you concatenate the two teams, preferably with a delimiter in between, eg:
=CONCATENATE(B2, "|", C2)
Use, for example Teams for the column header
Then, Insert ► Pivot Table and be sure to select to Add to Data Model
This adds the option for Distinct Counts to the Values Settings
Then Drag "league" to the Rows area, "Teams" to the Values area, and select Distinct Count for the Value Setting
You might get a table similar to below, which you can format in many different ways:
EXCEL SCREENSHOT=SUMPRODUCT(1/COUNTIFS($B$1:$B$7,B1:B7,$C$1:$C$7,C1:C7))
TRY THIS =SUMPRODUCT(1/COUNTIFS($B$1:$B$7,B1:B7,$C$1:$C$7,C1:C7))

Count Unique values for by category

I have a table with two columns, the first column has the neighbourhood name, and the second column contains a tree species. The table contains tens of thousands of rows (ie. there are multiple trees of each species in each neighbourhood) I need to know the number of different tree species in each neighbourhood. I got as far as using a pivot table to summarize and count the trees occurring in each neighbourhood, but the information that I am looking for is even more simple than this. How many unique tree species occur in each neighbourhood. I am using excel 2011 for mac. Can someone help me figure out the best way to do this?
With a PivotTable, one column for ROWS and the other for COLUMNS (either for Count of VALUES) you should only need to count the entries (either by row or by column, depending upon whether trees or neighbourhoods, and which you chose where).
If you don't want Pivot Tables, try the SubTotals feature as described by "rob" here: https://superuser.com/a/405569
You can also do this with the Subtotal feature.
Click the Data tab in Excel's ribbon toolbar
Click the Sort button and sort by your category column
Click the Subtotal button and fill in the dialog as appropriate, then click OK For example...
At each change in: Category
Use function: Sum
Add subtotal to: Cost of Goods Sold
i.e. have column titles in row 1, sort by neighbourhood, and subtotal "for each change in neighbourhood, use the count function and add the subtotal to trees"

Resources