sumif equivalent in microsoft access

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,159
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,203,236
Messages
6,054,297
Members
444,715
Latest member
GlitchHawk

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