can i do conditional sum in pivot table?

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Re: can you explain what you want?

i want to do the sub total sum based on some criteria (eg. col A="A", col B >100, etc)
 
Upvote 0
Can you elaborate? It would be best with an image of the setup, sample input data & sample output data. Thanks
 
Upvote 0
i have column A, B, C.
A contains type, B contains state, C contains data
I want to calculate sum of data based on criteria that type="A", state="B", is there a way to do so in pivot table?

I know i can do this use sumif, but can i use pivot table to do that?
seems i cannot use calculated field to achieve the result...:confused:

is there a way i can use IF in a calculated field? i enter formula =(if type="A", data, 0), but all the sum field shows 0, even those type is A ones..
 
Last edited:
Upvote 0
I think you're right about calculated fields not doing what you want. However the same result - with lots more functionality too - can be done via SQL. Exactly how it is implemented would depend on what was required. While I think of it, this can also be used to introduce nulls in the dataset.

Such as,
Code:
SELECT type, state, data, IIF(type='A',data,0) AS [New Name]
FROM YourTable
A null might be preferred, IIF(type='A',data,null) AS [New Field Name]

Criteria can be added,
Code:
SELECT type, state, data, IIF(type='A',data,0) AS [New Name]
FROM YourTable
WHERE type IN ('A','B') OR state = 'happy'

SQL can do powerful data handling simply.

A manual way to do this is from a new workbook (separate to the data) and menu ALT-D-P taking the external data option at the first step, then follow the wizard. Easier if you give the source data a non-dynamic defined name before starting. At the last step of the wizard take the option to edit in MS Query. Then the 'SQL' button to edit the SQL & the 'open door' button is one way to exit MS Query & complete the pivot table.

HTH
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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