sumif equivalent in microsoft access

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,160
If I have a table such as:

[Color] [Number of Colors]
Red 5
Orange 19
Red 9
Green 18
Orange 23

and want to add another column:

[Color] [Number of Colors] [Total Number of This Color]
Red 5 14
Orange 19 42
Red 9 14
Green 18 18
Orange 23 42

In excel, the sumif command does this easily, but in Access, what is the best way to add a conditional sum field that uses each record as a reference?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Use a totals query.

Group by Color and Sum Number of Colors.

The SQL would look something like this.

SELECT ColorTable.Color, Sum(ColorTable.[Number of Colors]) AS [SumOfNumber of Colors]
FROM ColorTable
GROUP BY ColorTable.Color;

If you want the exact layout you've posted use DSum.

DSum("[ColorTable]![Number of Colors]","[ColorTable]","[ColorTable]![Color]='" & [Color] & "'")
 
Upvote 0

Forum statistics

Threads
1,215,239
Messages
6,123,816
Members
449,127
Latest member
Cyko

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