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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,534
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,176,413
Messages
5,902,954
Members
435,002
Latest member
chenmoti

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