Criteria counting only for one field

Griffith

New Member
Joined
Aug 3, 2009
Messages
32
Hi,

I'm using Access 2003 for the following:

I Have the following fields in my table:

Materialnr Vendor Type Value

There are 2 different types (same materialnr can occur with each type): "Repair" and "non-repair". Now I want to make a query that creates the following columns:

Material (group by); vendor (group by); Sum of Value where type is Repair; Sum of value of all types

Is there any way to do this? When I try to put Repair as a criterium to get only "Repair" types it will also filter the values of the last column...

Thanks in advance!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,951
Office Version
  1. 365
Platform
  1. Windows
Assuming your table is named Table1, this code should work:
Code:
SELECT 
    Table1.Materialnr
    , Table1.Vendor
    , Sum(IIf([Table1]![Type]="Repair",[Table1]![Value],0)) AS RepairValue
    , Sum(Table1.Value) AS TotalValue
FROM 
    Table1
GROUP BY 
    Table1.Materialnr
    , Table1.Vendor;
 

Forum statistics

Threads
1,141,140
Messages
5,704,522
Members
421,353
Latest member
jekoxien15

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
Top