sumif equivalent in microsoft access

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,139
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 =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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] & "'")
 

Forum statistics

Threads
1,171,585
Messages
5,876,309
Members
433,193
Latest member
BruxoTrader

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