An individual might need to sum up only the values that satisfy certain criteria from a large dataset. The DSUM function can be very useful if we want to add values based on multiple conditions or criteria in Excel. In this article, we will show you two examples of how to use the DSUM function with multiple criteria in Excel.
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
2 Suitable Examples to Use DSUM Function with Multiple Criteria in Excel
In this article, we will demonstrate two suitable examples of how to use the DSUM function with multiple criteria in Excel. Here’s an overview of the dataset for our today’s task.
Example 1: Calculating Total Price Using DSUM Function with Multiple Criteria
In this example, we will calculate the total price of a product using the DSUM function with multiple criteria in Excel. We will walk you through the steps to do so.
Steps:
- First of all, create a table with all the imposed criteria you want.
- In this example, we want to calculate the Total Price for the following four criteria:
- Employee: Zack
- Date: > 31-05-2022
- Product: Earbuds
- Quantity Sold >= 50
- Then select cell F21 and write down the following formula.
=DSUM(B4:F16,"Total Price",B20:E21)
- After that, press Enter , and you will have the total price for all imposed criteria.
- Only rows 8 and 16 satisfy the four specified criteria in this example. If we sum up the total price of these two rows, we will get the exact result we got with the DSUM function.
Read More: How to Use Database Functions in Excel (With Examples)
Example 2: Calculate Total Price of Specified Entries Using VBA
In this example, we will run a VBA code to calculate the total price of specified entries. Read the following steps to learn how to do it.
Steps:
- First, press Alt + F11 to open the Microsoft Visual Basic window.
- Next, from the Insert tab, go to,
Insert → Module
- Then copy the following code and paste it to the Module window.
Sub DSUM_VBA()
Range("F21").Value = Application.WorksheetFunction.DSum(Range("B4:F16"), "Total Price", Range("B20:E21"))
End Sub
- After that, press F5 to run the code and go back to your worksheet.
- As a result, you will have the total price for the specified multiple criteria.
- Don’t forget to give proper cell references, or you won’t get the desired result.
- Make sure that the specified criteria range does not overlap the table.
Read More: How to Use DCOUNT Function in Excel (5 Suitable Examples)
Conclusion
Thanks for making it this far. I hope you find this article useful. Now you know two suitable examples of using the DSUM function with multiple criteria. Please let us know if you have any further queries, and feel free to give us any recommendations in the comment section below.