CountIf - Pivot Table

gehusi

Board Regular
Joined
Jul 20, 2010
Messages
182
Hello, I'm wondering if it is possible to input a COUNTIF function in calculated field in a pivot table. I'd like a field which counts the number of nonzero values for each data field in the pivot table. If what I'd like to do isn't possible using the calculated field functionality, can anyone think of another option?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

I'm not 100% clear on the requirement- some sample data would help.

It sounds like adding an extra field via SQL will do what you want - this is a more powerful option than calculated fields.

One way it can be set up is to give the source data a defined name, not dynamic. Then from a separate file start the pivot table wizard (ALT-D-P) and at the first step take the external data option. Follow the wizard to the end and choose the option to edit in MS Query. Then edit the SQL via the 'SQL' button. The 'open door' icon then exits MS Query & you can complete the pivot table. SQL needs to be specific to your requirement - as that isn't clear, sample SQL below is indicative only. Resultant worksheet containing the pivot table can be moved into the original source data file if you like.

HTH, Fazza

Code:
SELECT *, IIF(YourDataFieldName<>0,1,0) AS [Name For New Field]
FROM NameOfYourSourceData

PS

I've assumed the data field has numbers. If you may have nulls originally in the data, the conditional would have to expand to consider that. If you field name contains spaces or special characters, I think you'll need to enter it in the SQL as either 'name with space' or [name with space] instead of as above YourDataFieldName

Also, I noticed your post only by chance. I suggest it might be better to leave unanswered posts unbumped: then they show as unanswered and draw attention, otherwise once bumped they disappear into the zillions of other posts. :)
 
Upvote 0

Forum statistics

Threads
1,223,922
Messages
6,175,382
Members
452,639
Latest member
RMH2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top