问题
I have a workbook with multiple sheets. On sheet1 I would like to count the number of times person in column A has a particular entry in Column C that meets criteria of column D = Content but only count if column B is a unique value.
Using the below formula I can do everything except only counting unique numbers in Column B. I enter this formula in Sheet2 C2 then pull across to I2 then pull down to 6 in each column.
=IF(COUNTIFS(Sheet1!$A$2:$A$150,Sheet2!$B2,Sheet1!$C$2:$C$150,Sheet2!C$1,Sheet1!$D$2:$D$150,"Content")=0,"",COUNTIFS(Sheet1!$A$2:$A$150,Sheet2!$B2,Sheet1!$C$2:$C$150,Sheet2!C$1,Sheet1!$D$2:$D$150,"Content"))
I am using the double countifs to not show 0's.
Here is what it looks like for Sheet1
Here is how I would like Sheet 2 to look
Any help or advise would be much appreciated.
回答1:
You can achieve this via Pivot table.
- Select all data
- Insert ->Pivot table
- In the pop up ensure you check the check box at the bottom with description "Add this data to data Model" and then click OK. This will create Sheet 2 for you.
In The Pivot table fields Move "SR" to Rows section "Stage" to column section "Prod" to filter section "QN" to Value section
Now right click on some cell in Pivot which shows sum/count of QN Summarize values by -> More optins
- In the pop up, scroll to bottom and click on "Distinct Count"
- In the filter section of pivot (first row on pivot table which states "Prod"), choose "Content"
Note: Distinct count won't appear in values section if step 3 is missed out. Hope this helps.
回答2:
The answer by Vijayakumar works. In case you need a simpler version (without the data model option, use this formula in column E dragged down
=SUMPRODUCT(--($B$1:B1=B2))>0
- Select all data
- Insert ->Pivot table
- In The Pivot table fields Move "SR" to Rows section "Stage" to column section "Prod" & "IsUnique" (
Col E
) to filter section and "QN" to Value section - Now right click on some cell in Pivot which shows sum/count of QN Summarize values by -> Count
- In the filter section of pivot (first row on pivot table which states "Prod"), choose "Content"
- In the filter section of pivot (Second row on pivot table which states "IsUnique"), choose "TRUE"
When you have new data, you just need to Change Data Source
from the Pivot Table tools
->Analyze
or Refresh. However you can record this whole process as macro to automate it.
来源:https://stackoverflow.com/questions/41456189/excel-count-unique-value-multiple-columns