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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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;
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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